Skip to content

Commit

Permalink
feat($Exception): capture BadCredentialsException
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed May 9, 2020
1 parent d7b3802 commit 9e31637
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.val;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
Expand Down Expand Up @@ -110,6 +111,12 @@ public ResponseBodyBean<Object> handleException(HttpServletRequest request,
log.error("[GlobalExceptionCapture]: Exception information: {} ", exception.getMessage());
response.setStatus(HttpStatus.BAD_REQUEST.getCode());
return ResponseBodyBean.ofStatus(HttpStatus.BAD_REQUEST.getCode(), exception.getMessage(), null);
} else if (exception instanceof BadCredentialsException) {
// IMPORTANT: org.springframework.security.authentication.BadCredentialsException only exists in the project
// that depends on org.springframework.boot.spring-boot-starter-security
log.error("[GlobalExceptionCapture]: Exception information: {} ", exception.getMessage());
response.setStatus(HttpStatus.BAD_CREDENTIALS.getCode());
return ResponseBodyBean.ofStatus(HttpStatus.BAD_CREDENTIALS.getCode(), exception.getMessage(), null);
}
log.error("[GlobalExceptionCapture]: Exception information: {} ", exception.getMessage(), exception);
response.setStatus(HttpStatus.ERROR.getCode());
Expand Down

0 comments on commit 9e31637

Please sign in to comment.