ExceptionHandler 코드를 작성하는 도중 의문점이 들었다.
왜 꼭 "ResponseEntity"로 return 해야 하는지. 그냥 "ErrorResponse"로 해도 같은 형태로 응답이 오던데,,,
문제는 바로 HttpStatus였다.
Error인데 200으로 응답되더라!
ResponseEntity에 status 잘해서 넘겨주기.
@ExceptionHandler(CommonException.class)
public ResponseEntity customJwtException(CommonException e) {
e.printStackTrace();
log.warn("CommonException : {}", e.getResponseCode().getDescription());
return ResponseEntity
.status(e.getResponseCode().getHttpStatus())
.body(new ErrorResponse(e.getResponseCode()));
}
'Back-End > SpringBoot' 카테고리의 다른 글
[SpringBoot] Executors.newFixedThreadPool() 코드의 이슈(자원 반환해주기) (0) | 2023.05.27 |
---|---|
[SpringBoot/Java17] Java 17 Record 활용(nested class, @Builder 사용, Class와 비교) (1) | 2022.12.31 |
[SpringBoot/Java17] java 17 SunJCE 오류 해결(vm option 추가) (0) | 2022.12.12 |
[SpringBoot] version upgrade (0) | 2022.10.23 |
[SpringBoot/QueryDsl] java.lang.IllegalArgumentException: Multiple entries with same key (0) | 2022.09.04 |