-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] :: exception advice class add
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/project/qvick/global/exception/ExceptionAdvice.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,30 @@ | ||
package com.project.qvick.global.exception; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class ExceptionAdvice { | ||
|
||
@Getter | ||
@Builder | ||
@RequiredArgsConstructor | ||
private static class ErrorResponse { | ||
private final int status; | ||
private final String message; | ||
} | ||
|
||
@ExceptionHandler({BusinessException.class}) | ||
public ResponseEntity<ErrorResponse> handleException(BusinessException ex) { | ||
ErrorResponse response = ErrorResponse.builder() | ||
.status(ex.getError().getStatus().value()) | ||
.message(ex.getError().getMessage()) | ||
.build(); | ||
return new ResponseEntity<ErrorResponse>(response, ex.getError().getStatus()); | ||
} | ||
|
||
} |