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

log/#301 GlobalExceptionHandler 로그 추가 #302

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
Expand Up @@ -6,6 +6,7 @@
import static io.oeid.mogakgo.exception.code.ErrorCode401.AUTH_TOKEN_EXPIRED;
import static io.oeid.mogakgo.exception.code.ErrorCode403.AUTH_ACCESS_DENIED;
import static io.oeid.mogakgo.exception.code.ErrorCode500.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class GlobalExceptionHandler {
protected ResponseEntity<ErrorResponse> handleCustomException(
CustomException e, HttpServletRequest request
) {
log.debug("Custom Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
return ErrorResponse.from(e.getErrorCode());
}

Expand All @@ -44,6 +46,7 @@ protected ResponseEntity<ErrorResponse> validationException(
BindException e,
HttpServletRequest request
) {
log.debug("Validation Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
BindingResult bindingResult = e.getBindingResult();

StringBuilder builder = new StringBuilder();
Expand All @@ -69,38 +72,40 @@ protected ResponseEntity<ErrorResponse> validationException(
public ResponseEntity<ErrorResponse> missingPathVariableException(
Exception e, HttpServletRequest request
) {
log.debug("Missing Path Variable Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
return ErrorResponse.from(PATH_PARAMETER_BAD_REQUEST);
}

@ExceptionHandler(value = {TokenExpiredException.class})
protected ResponseEntity<ErrorResponse> handleTokenExpiredException(
TokenExpiredException e, HttpServletRequest request
) {
log.warn("Token Expired: {}", e.getMessage());
log.debug("Token Expiry Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
return ErrorResponse.from(AUTH_TOKEN_EXPIRED);
}

@ExceptionHandler(value = {AuthenticationException.class, JWTVerificationException.class})
protected ResponseEntity<ErrorResponse> handleAuthenticationException(
AuthenticationException e, HttpServletRequest request
) {
log.warn("Authentication Exception: {}", e.getMessage());
log.debug("AuthenticationException Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
log.debug("Token: {}", request.getHeader(AUTHORIZATION));
return ErrorResponse.from(AUTH_MISSING_CREDENTIALS);
}

@ExceptionHandler(value = {AccessDeniedException.class})
protected ResponseEntity<ErrorResponse> handleAccessDeniedException(
AccessDeniedException e, HttpServletRequest request
) {
log.warn("Access Denied: {}", e.getMessage());
log.debug("Access Denied: {}, Path: {}", e.getMessage(), request.getPathInfo());
return ErrorResponse.from(AUTH_ACCESS_DENIED);
}

@ExceptionHandler(value = Exception.class)
protected ResponseEntity<ErrorResponse> handleException(
Exception e, HttpServletRequest request
) {
log.error("error", e);
log.debug("Exception: {}, Path: {}", e.getMessage(), request.getPathInfo());
return ErrorResponse.from(INTERNAL_SERVER_ERROR);
}
}
Loading