diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/exceptions/ControllerExceptionHandler.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/exceptions/ControllerExceptionHandler.java index 6ea6ca5..a585402 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/exceptions/ControllerExceptionHandler.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/exceptions/ControllerExceptionHandler.java @@ -13,40 +13,21 @@ import br.com.rayankonecny.hdcommoslib.models.exceptions.StandardError; import br.com.rayankonecny.hdcommoslib.models.exceptions.ValidationException; import static java.time.LocalDateTime.now; -import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.HttpStatus.BAD_REQUEST; import java.util.ArrayList; - @ControllerAdvice public class ControllerExceptionHandler { - // @ExceptionHandler(UsernameNotFoundException.class) - // ResponseEntity handleNotAuthorizedException(final UsernameNotFoundException ex,final HttpServletRequest request) { + @ExceptionHandler({ BadCredentialsException.class, RefreshTokenExpired.class, UsernameNotFoundException.class }) + ResponseEntity handleBadCredentialsException(final RuntimeException ex, + final HttpServletRequest request) { - // return ResponseEntity.status(UNAUTHORIZED).body( - // StandardError.builder() - // .timestamp(now()) - // .status(UNAUTHORIZED.value()) - // .error(UNAUTHORIZED.getReasonPhrase()) - // .message(ex.getMessage()) - // .path(request.getRequestURI()) - // .build()); - // } - - @ExceptionHandler({BadCredentialsException.class,RefreshTokenExpired.class,UsernameNotFoundException.class}) - ResponseEntity handleBadCredentialsException(final RuntimeException ex, final HttpServletRequest request) { - - return ResponseEntity.status(UNAUTHORIZED).body( - StandardError.builder() - .timestamp(now()) - .status(UNAUTHORIZED.value()) - .error(UNAUTHORIZED.getReasonPhrase()) - .message(ex.getMessage()) - .path(request.getRequestURI()) - .build()); + return ResponseEntity.status(UNAUTHORIZED) + .body(StandardError.builder().timestamp(now()).status(UNAUTHORIZED.value()) + .error(UNAUTHORIZED.getReasonPhrase()).message(ex.getMessage()).path(request.getRequestURI()).build()); } @ExceptionHandler(MethodArgumentNotValidException.class)