@Test public void testUnauthorizedUserException() { UnauthorizedUserException ex = new UnauthorizedUserException("Missing user credentials"); assertEquals(HttpStatus.UNAUTHORIZED, exceptionHandler.handleUnauthorizedException(ex).getStatusCode()); }
@ResponseBody @ExceptionHandler(UnauthorizedUserException.class) public ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex) { String message = ex.getMessage(); LOGGER.error(message); HttpStatus status = HttpStatus.UNAUTHORIZED; ErrorResponse errorResponse = buildErrorResponse(status.value(), message); return ResponseEntity.status(status).body(errorResponse); }
WebResourceExceptionHandler { @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) public ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex) { String message = ex.getMessage(); LOGGER.error(message); HttpStatus status = HttpStatus.UNAUTHORIZED; ErrorResponse errorResponse = buildErrorResponse(status.value(), message); return ResponseEntity.status(status).body(errorResponse); } }
WebResourceExceptionHandler { @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) public ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex) { String message = ex.getMessage(); LOGGER.error(message); HttpStatus status = HttpStatus.UNAUTHORIZED; ErrorResponse errorResponse = buildErrorResponse(status.value(), message); return ResponseEntity.status(status).body(errorResponse); }  }
WebResourceExceptionHandler { @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) public ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex) { String message = ex.getMessage(); LOGGER.error(message); HttpStatus status = HttpStatus.UNAUTHORIZED; ErrorResponse errorResponse = buildErrorResponse(status.value(), message); return ResponseEntity.status(status).body(errorResponse); }  @ResponseBody @ExceptionHandler(IntegrationUnavailableException.class) ResponseEntity<ErrorResponse> handleUnavailableException(IntegrationUnavailableException ex); @ResponseBody @ExceptionHandler({RemoteApiException.class}) ResponseEntity<ErrorResponse> handleRemoteAPIException(RemoteApiException ex); @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex); @ResponseBody @ExceptionHandler({ ForbiddenAuthException.class, UnregisteredAppAuthException.class }) ResponseEntity<ErrorResponse> handleForbiddenException(AuthenticationException ex); @ResponseBody @ExceptionHandler(MissingRequiredParameterException.class) ResponseEntity<ErrorResponse> handleMissingRequiredParameterException(MissingRequiredParameterException ex); }
WebResourceExceptionHandler { @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) public ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex) { String message = ex.getMessage(); LOGGER.error(message); HttpStatus status = HttpStatus.UNAUTHORIZED; ErrorResponse errorResponse = buildErrorResponse(status.value(), message); return ResponseEntity.status(status).body(errorResponse); }  @ResponseBody @ExceptionHandler(IntegrationUnavailableException.class) ResponseEntity<ErrorResponse> handleUnavailableException(IntegrationUnavailableException ex); @ResponseBody @ExceptionHandler({RemoteApiException.class}) ResponseEntity<ErrorResponse> handleRemoteAPIException(RemoteApiException ex); @ResponseBody @ExceptionHandler(UnauthorizedUserException.class) ResponseEntity<ErrorResponse> handleUnauthorizedException(UnauthorizedUserException ex); @ResponseBody @ExceptionHandler({ ForbiddenAuthException.class, UnregisteredAppAuthException.class }) ResponseEntity<ErrorResponse> handleForbiddenException(AuthenticationException ex); @ResponseBody @ExceptionHandler(MissingRequiredParameterException.class) ResponseEntity<ErrorResponse> handleMissingRequiredParameterException(MissingRequiredParameterException ex);  }