Skip to content

Commit

Permalink
feat: exception handler 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gitchannn committed Nov 1, 2023
1 parent dee1efd commit 2d94e8c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sallange.server.api.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ExceptionResponse {

private String exceptionMessage;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package sallange.server.api.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import sallange.server.exception.RentException;
import sallange.server.exception.UnAuthorizationException;

@ControllerAdvice
public class GlobalExceptionHandler {
Expand All @@ -14,4 +16,18 @@ public ResponseEntity<RentExceptionResponse> handleRentException(final RentExcep
.badRequest()
.body(new RentExceptionResponse(e.getErrorCode(), e.getMessage()));
}

@ExceptionHandler(UnAuthorizationException.class)
public ResponseEntity<ExceptionResponse> handleUnAuthorizationException(final UnAuthorizationException e) {
return ResponseEntity
.status(HttpStatus.UNAUTHORIZED)
.body(new ExceptionResponse(e.getExceptionMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ExceptionResponse> handleException(final Exception e) {
return ResponseEntity
.internalServerError()
.body(new ExceptionResponse(e.getMessage()));
}
}

0 comments on commit 2d94e8c

Please sign in to comment.