Conversation
| public ResponseEntity<ErrorResponse> RequestNullExistException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.REQUEST_NULL_VALUE); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(400)); | ||
| } | ||
|
|
||
| @ExceptionHandler(MemberNotExistException.class) | ||
| public ResponseEntity<ErrorResponse> MemberNotExistException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.MEMBER_NOT_EXIST); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(400)); | ||
| } | ||
|
|
||
| @ExceptionHandler(BoardNotExistException.class) | ||
| public ResponseEntity<ErrorResponse> BoardNotExistException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.BOARD_NOT_EXIST); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(400)); | ||
| } | ||
|
|
||
| @ExceptionHandler(ArticleNotFoundException.class) | ||
| public ResponseEntity<ErrorResponse> ArticleNotFoundException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.ARTICLE_NOT_EXIST); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(404)); | ||
| } | ||
|
|
||
| @ExceptionHandler(MemberNotFoundException.class) | ||
| public ResponseEntity<ErrorResponse> MemberNotFoundException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.MEMBER_NOT_FOUND); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(404)); | ||
| } | ||
|
|
||
| @ExceptionHandler(BoardNotFoundException.class) | ||
| public ResponseEntity<ErrorResponse> BoardNotFoundException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.BOARD_NOT_FOUND); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(404)); | ||
| } | ||
|
|
||
| @ExceptionHandler(AlreadyHasEmailException.class) | ||
| public ResponseEntity<ErrorResponse> AlreadyHasEmailException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.EMAIL_EXIST); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(409)); | ||
| } | ||
|
|
||
| @ExceptionHandler(MemberHasArticleException.class) | ||
| public ResponseEntity<ErrorResponse> MemberHasArticleException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.MEMBER_ARTICLE_EXIST); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(400)); | ||
| } | ||
|
|
||
| @ExceptionHandler(BoardHasArticleException.class) | ||
| public ResponseEntity<ErrorResponse> BoardHasArticleException() { |
There was a problem hiding this comment.
넵 제외하겠습니다! 궁금해서 묻는건데 제외하는 이유가 있나요??
There was a problem hiding this comment.
application.yml에는 유출되면 보안에 치명적인 정보가 많이 들어있어요.
그래서 원격에 올릴 경우 막대한 피해를 보게 될 수도 있어서 application.yml등과 같은 민감한 파일은 올리지 않는 것이 좋아요.
| private final int status; | ||
| private final String code; |
There was a problem hiding this comment.
Status Code는 상태 코드라고 불리며 숫자로 나타냅니다.
결국 Status Code는 상태를 나타내는 코드(숫자)를 의미한다고 생각해요.
따라서 code가 int, status가 String이어야 된다고 생각해요.
status가 int, code가 String인 이유가 있나요?
There was a problem hiding this comment.
앗... 지금 보니까 설정이 뒤바뀌었네요.. 고치도록 할게요!
| @ExceptionHandler(RequestNullExistException.class) | ||
| public ResponseEntity<ErrorResponse> RequestNullExistException() { | ||
| ErrorResponse response = new ErrorResponse(ErrorCode.REQUEST_NULL_VALUE); | ||
| return new ResponseEntity<>(response, HttpStatusCode.valueOf(400)); |
There was a problem hiding this comment.
ErrorCode.REQUEST_NULL_VALUE.getStatus()를 안쓰고 HttpStatus.valueOf(400)로 직접 지정한 이유가 있나요?
There was a problem hiding this comment.
getStatus를 써도 같은 결과가 발생하는 군요! 하나 더 배워갑니다!
| public class GlobalExceptionHandler { | ||
|
|
||
| @ExceptionHandler(RequestNullExistException.class) | ||
| public ResponseEntity<ErrorResponse> RequestNullExistException() { |
There was a problem hiding this comment.
Exception에 message가 담겨있는 message를 반환해야할 경우에는 어떻게 핸들링 해야할지 생각해보세요 :)
There was a problem hiding this comment.
사용자 지정 Exception 매개변수에 message를 넣어서 반환하면 됩니다!
감사합니다.👍 |
구글 문서에 작성해두겠습니다.