Skip to content

Conversation

@jabell0310
Copy link

구글 문서에 작성해두겠습니다.

Copy link

@ImTotem ImTotem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다
점점 깔끔해지는게 보이네요

Comment on lines 12 to 60
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() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 naming convention은 지켜주세요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

참고하고 다음 실습 때 고치도록 하겠습니다!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitignore로 제외해주세요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 제외하겠습니다! 궁금해서 묻는건데 제외하는 이유가 있나요??

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.yml에는 유출되면 보안에 치명적인 정보가 많이 들어있어요.
그래서 원격에 올릴 경우 막대한 피해를 보게 될 수도 있어서 application.yml등과 같은 민감한 파일은 올리지 않는 것이 좋아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 그렇군요! 알겠습니다!

Comment on lines 21 to 22
private final int status;
private final String code;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status Code는 상태 코드라고 불리며 숫자로 나타냅니다.
결국 Status Code는 상태를 나타내는 코드(숫자)를 의미한다고 생각해요.
따라서 code가 int, status가 String이어야 된다고 생각해요.

status가 int, code가 String인 이유가 있나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗... 지금 보니까 설정이 뒤바뀌었네요.. 고치도록 할게요!

@ExceptionHandler(RequestNullExistException.class)
public ResponseEntity<ErrorResponse> RequestNullExistException() {
ErrorResponse response = new ErrorResponse(ErrorCode.REQUEST_NULL_VALUE);
return new ResponseEntity<>(response, HttpStatusCode.valueOf(400));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorCode.REQUEST_NULL_VALUE.getStatus()를 안쓰고 HttpStatus.valueOf(400)로 직접 지정한 이유가 있나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStatus를 써도 같은 결과가 발생하는 군요! 하나 더 배워갑니다!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔 하네요 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

public class GlobalExceptionHandler {

@ExceptionHandler(RequestNullExistException.class)
public ResponseEntity<ErrorResponse> RequestNullExistException() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception에 message가 담겨있는 message를 반환해야할 경우에는 어떻게 핸들링 해야할지 생각해보세요 :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자 지정 Exception 매개변수에 message를 넣어서 반환하면 됩니다!

@jabell0310
Copy link
Author

고생하셨습니다 점점 깔끔해지는게 보이네요

감사합니다.👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants