Skip to content

Commit

Permalink
fix: 예외에서 정의한 메세지를 꺼내지 못하는 오류 해결 (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunsanglee authored Jul 25, 2024
1 parent 7b92958 commit c85f71e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public record ErrorResponse(
String message
) {

public static ErrorResponse of(HaengdongErrorCode errorCode) {
return new ErrorResponse(errorCode.getMessage());
public static ErrorResponse of(String message) {
return new ErrorResponse(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ErrorResponse> haengdongException() {
return ResponseEntity.badRequest()
.body(ErrorResponse.of(HaengdongErrorCode.BAD_REQUEST));
.body(ErrorResponse.of(HaengdongErrorCode.BAD_REQUEST.getMessage()));
}

@ExceptionHandler(MethodArgumentNotValidException.class)
Expand All @@ -25,19 +25,19 @@ public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(Metho
.collect(Collectors.joining(", "));

return ResponseEntity.badRequest()
.body(new ErrorResponse(errorMessage));
.body(ErrorResponse.of(errorMessage));
}

@ExceptionHandler(HaengdongException.class)
public ResponseEntity<ErrorResponse> haengdongException(HaengdongException e) {
return ResponseEntity.status(e.getStatusCode())
.body(ErrorResponse.of(e.getErrorCode()));
.body(ErrorResponse.of(e.getMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
log.error(e.getMessage(), e);
return ResponseEntity.internalServerError()
.body(ErrorResponse.of(HaengdongErrorCode.INTERNAL_SERVER_ERROR));
.body(ErrorResponse.of(HaengdongErrorCode.INTERNAL_SERVER_ERROR.getMessage()));
}
}

0 comments on commit c85f71e

Please sign in to comment.