Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 핸들링 되고 있지 않은 커스텀 에러 핸들러 추가 #959

Open
wants to merge 5 commits into
base: BE/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import lombok.extern.slf4j.Slf4j;
import site.coduo.common.controller.response.ApiErrorResponse;
import site.coduo.member.controller.error.MemberApiError;
import site.coduo.member.exception.AuthenticationException;
import site.coduo.member.exception.ExternalApiCallException;
import site.coduo.member.exception.InvalidMemberAddException;
import site.coduo.member.exception.MemberException;
import site.coduo.member.exception.MemberNotFoundException;

@Slf4j
Expand Down Expand Up @@ -41,4 +43,20 @@ public ResponseEntity<ApiErrorResponse> handlerExternalApiCallFailureException(f
return ResponseEntity.status(MemberApiError.API_CALL_FAILURE_ERROR.getHttpStatus())
.body(new ApiErrorResponse(MemberApiError.MEMBER_NOT_FOUND_ERROR.getMessage()));
}

@ExceptionHandler(AuthenticationException.class)
public ResponseEntity<ApiErrorResponse> handlerAuthenticationException(final AuthenticationException e) {
log.error(e.getMessage());

return ResponseEntity.status(MemberApiError.AUTHENTICATION_ERROR.getHttpStatus())
.body(new ApiErrorResponse(MemberApiError.AUTHENTICATION_ERROR.getMessage()));
}

@ExceptionHandler(MemberException.class)
public ResponseEntity<ApiErrorResponse> handlerMemberException(final MemberException e) {
log.error(e.getMessage());

return ResponseEntity.status(MemberApiError.INVALID_MEMBER_REQUEST.getHttpStatus())
.body(new ApiErrorResponse(MemberApiError.INVALID_MEMBER_REQUEST.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum MemberApiError {
AUTHENTICATION_ERROR(HttpStatus.UNAUTHORIZED, "인증되지 않은 접근입니다."),
MEMBER_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."),
INVALID_ADD_MEMBER_ERROR(HttpStatus.BAD_REQUEST, "자신의 아이디로 페어 정보 연동을 할 수 없습니다."),
API_CALL_FAILURE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "외부 API와 상호작용 중 실패했습니다.");
API_CALL_FAILURE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "외부 API와 상호작용 중 실패했습니다."),
INVALID_MEMBER_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 사용자 관련 요청입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ResponseEntity<ApiErrorResponse> handlePairRoomMemberNotFoundException(
public ResponseEntity<ApiErrorResponse> handlePairRoomException(final PairRoomException e) {
log.warn(e.getMessage());

return ResponseEntity.status(PairRoomApiError.INVALID_REQUEST.getHttpStatus())
.body(new ApiErrorResponse(PairRoomApiError.INVALID_REQUEST.getMessage()));
return ResponseEntity.status(PairRoomApiError.INVALID_PAIR_ROOM_REQUEST.getHttpStatus())
.body(new ApiErrorResponse(PairRoomApiError.INVALID_PAIR_ROOM_REQUEST.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@RequiredArgsConstructor
public enum PairRoomApiError {

INVALID_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 요청입니다."),
INVALID_PAIR_ROOM_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 페어룸 관련 요청입니다."),
INVALID_PAIR_NAME(HttpStatus.BAD_REQUEST, "올바르지 않은 페어 이름입니다."),
INVALID_ACCESS_CODE(HttpStatus.BAD_REQUEST, "올바르지 않은 접근 코드입니다."),
PAIR_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "페어룸이 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.extern.slf4j.Slf4j;
import site.coduo.common.controller.response.ApiErrorResponse;
import site.coduo.referencelink.controller.error.ReferenceLinkApiError;
import site.coduo.referencelink.exception.CategoryNotFoundException;
import site.coduo.referencelink.exception.InvalidCategoryException;
import site.coduo.referencelink.exception.InvalidUrlFormatException;
import site.coduo.referencelink.exception.ReferenceLinkException;

Expand All @@ -25,6 +27,22 @@ public ResponseEntity<ApiErrorResponse> handleInvalidUrlFormatException(final In
.body(new ApiErrorResponse(ReferenceLinkApiError.INVALID_URL_FORMAT.getMessage()));
}

@ExceptionHandler(CategoryNotFoundException.class)
public ResponseEntity<ApiErrorResponse> handleCategoryNotFoundException(final CategoryNotFoundException e) {
log.warn(e.getMessage());

return ResponseEntity.status(ReferenceLinkApiError.CATEGORY_NOT_FOUND.getHttpStatus())
.body(new ApiErrorResponse(ReferenceLinkApiError.CATEGORY_NOT_FOUND.getMessage()));
}

@ExceptionHandler(InvalidCategoryException.class)
public ResponseEntity<ApiErrorResponse> handleInvalidCategoryException(final InvalidCategoryException e) {
log.warn(e.getMessage());

return ResponseEntity.status(ReferenceLinkApiError.INVALID_CATEGORY_FORMAT.getHttpStatus())
.body(new ApiErrorResponse(ReferenceLinkApiError.INVALID_CATEGORY_FORMAT.getMessage()));
}

@ExceptionHandler(ReferenceLinkException.class)
public ResponseEntity<ApiErrorResponse> handleReferenceLinkException(final ReferenceLinkException e) {
log.warn(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public enum ReferenceLinkApiError {

INVALID_URL_FORMAT(HttpStatus.BAD_REQUEST, "올바르지 않은 URL 형식입니다."),
REFERENCE_LINK_NOT_FOUND(HttpStatus.NOT_FOUND, "링크 정보가 존재하지 않습니다."),
BAD_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 요청입니다.");
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "카테고리를 찾을 수 없습니다."),
INVALID_CATEGORY_FORMAT(HttpStatus.BAD_REQUEST, "올바르지 않은 카테고리 형식입니다."),
BAD_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 카테고리 혹은 레퍼런스 링크 요청입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ public class RetrospectException extends RuntimeException {
public RetrospectException(final String message) {
super(message);
}

public RetrospectException(final String message, final Throwable cause) {
super(message, cause);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,46 @@
import lombok.extern.slf4j.Slf4j;
import site.coduo.common.controller.response.ApiErrorResponse;
import site.coduo.todo.controller.error.TodoApiError;
import site.coduo.todo.exception.InvalidTodoContentException;
import site.coduo.todo.exception.InvalidUpdatedTodoSortException;
import site.coduo.todo.exception.TodoException;
import site.coduo.todo.exception.TodoNotFoundException;

@Slf4j
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class TodoExceptionHandler {

@ExceptionHandler(InvalidTodoContentException.class)
public ResponseEntity<ApiErrorResponse> handleInvalidTodoContentException(final InvalidTodoContentException e) {
log.warn(e.getMessage());

return ResponseEntity.status(TodoApiError.INVALID_TODO_CONTENT_FORMAT.getHttpStatus())
.body(new ApiErrorResponse(TodoApiError.INVALID_TODO_CONTENT_FORMAT.getMessage()));
}

@ExceptionHandler(InvalidUpdatedTodoSortException.class)
public ResponseEntity<ApiErrorResponse> handleInvalidUpdatedTodoSortException(
final InvalidUpdatedTodoSortException e) {
log.warn(e.getMessage());

return ResponseEntity.status(TodoApiError.INVALID_TODO_SORT.getHttpStatus())
.body(new ApiErrorResponse(TodoApiError.INVALID_TODO_SORT.getMessage()));
}

@ExceptionHandler(TodoNotFoundException.class)
public ResponseEntity<ApiErrorResponse> handleTodoNotFoundException(final TodoNotFoundException e) {
log.warn(e.getMessage());

return ResponseEntity.status(TodoApiError.TODO_NOT_FOUND.getHttpStatus())
.body(new ApiErrorResponse(TodoApiError.TODO_NOT_FOUND.getMessage()));
}

@ExceptionHandler(TodoException.class)
public ResponseEntity<ApiErrorResponse> handleTodoException(final TodoException e) {
log.warn(e.getMessage());

return ResponseEntity.status(TodoApiError.INVALID_TODO_REQUEST.getHttpStatus())
.body(new ApiErrorResponse(e.getMessage()));
.body(new ApiErrorResponse(TodoApiError.INVALID_TODO_REQUEST.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@RequiredArgsConstructor
public enum TodoApiError {

TODO_NOT_FOUND(HttpStatus.NOT_FOUND, "투두를 찾을 수 없습니다."),
INVALID_TODO_SORT(HttpStatus.BAD_REQUEST, "유효하지 않은 투두 순서입니다."),
INVALID_TODO_CONTENT_FORMAT(HttpStatus.BAD_REQUEST, "유효하지 않은 투두 내용 형식입니다."),
INVALID_TODO_REQUEST(HttpStatus.BAD_REQUEST, "유효하지 않은 TODO 요청입니다.");

private final HttpStatus httpStatus;
Expand Down

This file was deleted.

Loading