일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- http
- kotlin
- 스프링
- Proxy
- 스프링 핵심 원리
- 백준
- Spring Boot
- JPQL
- pointcut
- QueryDSL
- db
- jpa
- Thymeleaf
- spring
- JDBC
- AOP
- SpringBoot
- 알고리즘
- Greedy
- 김영한
- 인프런
- Servlet
- 스프링 핵심 기능
- Android
- 자바
- Exception
- springdatajpa
- 그리디
- transaction
- java
- Today
- Total
목록@ExceptionHandler (5)
개발자되기 프로젝트
1. ErrorResponse 다음과 같이 Error발생시 Response를 내려준다고 해보자. data class ErrorResponse( @field:JsonProperty("result_code") var resultCode: String?=null, @field:JsonProperty("http_status") var httpStatus: String?=null, @field:JsonProperty("http_method") var httpMethod : String?= null, var message: String?=null, var path: String?=null, var timestamp: LocalDateTime?= null, var errors: MutableList? = mutabl..
[API예외] @ControllerAdvice @ExceptionHandler 를 사용해서 예외를 깔끔하게 처리할 수 있게 되었지만, 정상 코드와 예외 처리 코드가 하나의 컨트롤러에 섞여 있다. @ControllerAdvice 또는 @RestControllerAdvice 를 사용하면.. bsh-developer.tistory.com @ControllerAdvice는 Controller에서 발생하는 Exception을 어떻게 처리할지 따로 분류해서 관리할 수 있도록 도와줌. 말 그대로 Controller에 대한 Advice이다. 아래와 같이 IndexOutOfBounds Exception이 무조건 발생하는 Controller가 있다고 해보자. @RestController @RequestMapping("/a..
@ExceptionHandler 를 사용해서 예외를 깔끔하게 처리할 수 있게 되었지만, 정상 코드와 예외 처리 코드가 하나의 컨트롤러에 섞여 있다. @ControllerAdvice 또는 @RestControllerAdvice 를 사용하면 둘을 분리할 수 있다. 1.@ControllerAdvice Controller에 있던 오류 처리 코드를 분리해 내자. @RestControllerAdvice를 적용한 ExControllerAdvice 클래스를 생성하여 코드를 여기로 옮겨놓자. 그러면 여러 controller에서 발생한 Exception을 ControllerAdvice에서 처리해줌. @Slf4j @RestControllerAdvice public class ExControllerAdvice { @Respo..
1. HTML 화면 오류 & API 오류 웹 브라우저에 HTML 화면을 제공할 때는 오류가 발생하면 BasicErrorController 사용이 편함 이때는 단순히 5xx, 4xx 관련된 오류 화면을 보여주면 된다. BasicErrorController 는 이런 메커니즘을 모두 구현해둠. 그런데 API는 각 시스템 마다 응답의 모양도 다르고, 스펙도 모두 다르다. 예외 상황에 단순히 오류 화면을 보여주는 것이 아니라, 예외에 따라서 각각 다른 데이터를 출력해야 할 수도 있다. 그리고 같은 예외라고해도 어떤 컨트롤러에서 발생했는가에 따라서 다른 예외 응답을 내려주어야 할 수 있다. 즉 세밀한 제어가 필요하다. 2. API예외 처리의 어려운 점. HandlerExceptionResolver 를 떠올려 보면 ..
API예외 처리는 SpringBoot의 기본 오류 처리 방식을 사용할 수 있음. 1. BasicErrorController SpringBoot가 제공하는 기본 ErrorController @Controller @RequestMapping("${server.error.path:${error.path:/error}}") public class BasicErrorController extends AbstractErrorController { @RequestMapping(produces = MediaType.TEXT_HTML_VALUE) public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {} @Reques..