-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] global controller advice and dto
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/twtw/backend/global/advice/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.twtw.backend.global.advice; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ErrorResponse { | ||
private String message; | ||
} |
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/twtw/backend/global/advice/GlobalErrorAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.twtw.backend.global.advice; | ||
|
||
import com.twtw.backend.global.exception.EntityNotFoundException; | ||
import com.twtw.backend.global.exception.WebClientResponseException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalErrorAdvice { | ||
|
||
@ExceptionHandler(WebClientResponseException.class) | ||
public ResponseEntity<ErrorResponse> webClientResponse(final WebClientResponseException e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(EntityNotFoundException.class) | ||
public ResponseEntity<ErrorResponse> entityNotFound(final EntityNotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(e.getMessage())); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/twtw/backend/global/exception/EntityNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.twtw.backend.global.exception; | ||
|
||
public class EntityNotFoundException extends IllegalArgumentException { | ||
private static final String MESSAGE = "엔티티를 조회할 수 없습니다."; | ||
|
||
public EntityNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |