Skip to content

Commit

Permalink
[Feat] :: exception advice class add
Browse files Browse the repository at this point in the history
  • Loading branch information
lgwk42 committed May 11, 2024
1 parent 87cad33 commit 320cf49
Showing 1 changed file with 30 additions and 0 deletions.
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());
}

}

0 comments on commit 320cf49

Please sign in to comment.