File tree Expand file tree Collapse file tree
src/main/java/roomescape/advice Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package roomescape .advice ;
2+
3+ public record ErrorResponse (String message ) {
4+ }
Original file line number Diff line number Diff line change 1+ package roomescape .advice ;
2+
3+ import org .springframework .data .crossstore .ChangeSetPersister ;
4+ import org .springframework .http .ResponseEntity ;
5+ import org .springframework .web .bind .annotation .ControllerAdvice ;
6+ import org .springframework .web .bind .annotation .ExceptionHandler ;
7+
8+ @ ControllerAdvice
9+ public class GlobalExceptionHandler {
10+
11+ @ ExceptionHandler (IllegalArgumentException .class )
12+ public ResponseEntity <ErrorResponse > handleIllegalArgumentException (IllegalArgumentException e ) {
13+ return ResponseEntity .badRequest ()
14+ .body (new ErrorResponse (e .getMessage ()));
15+ }
16+
17+ @ ExceptionHandler (ChangeSetPersister .NotFoundException .class )
18+ public ResponseEntity <ErrorResponse > handleNotFoundException (RuntimeException e ) {
19+ return ResponseEntity .status (404 )
20+ .body (new ErrorResponse (e .getMessage ()));
21+ }
22+
23+ @ ExceptionHandler (Exception .class )
24+ public ResponseEntity <ErrorResponse > handleException (Exception e ) {
25+ return ResponseEntity .internalServerError ()
26+ .body (new ErrorResponse ("오류가 발생했습니다." ));
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments