본문 바로가기
Spring Boot

ExceptionHandler

by 상국이 2022. 2. 28.
728x90

스프링 @MVC에서 예외 처리 방법

@GetMapping("/exception")
public String exceptionExample(){
    throw new SampleException();
}

@ExceptionHandler(SampleException.class)
public AppError sampleError(SampleException exception){
    return AppError.builder()
            .message("App error")
            .reason("na do mola")
            .build();
}

 

결과

 

커스텀 에러 페이지

/static/error 밑에 html페이지 생성 > error code와 같으면 좋음

결과

728x90

'Spring Boot' 카테고리의 다른 글

CORS  (0) 2022.02.28
HATEOAS  (0) 2022.02.28
문법  (0) 2022.02.28
HtmlUnit  (0) 2022.02.28
Thymeleaf  (0) 2022.02.28

댓글