Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exception handler 추가 #11

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
}