Skip to content

Commit

Permalink
feat: 투두 예외 핸들러 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHyeonL committed Nov 12, 2024
1 parent e2aa437 commit fa8cda6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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

0 comments on commit fa8cda6

Please sign in to comment.