@Test public void shouldResolveUnhandledException() throws Exception { when(messageService.message(UNEXPECTED_EXCEPTION)).thenReturn("Oops, something has gone wrong. Please try again later"); final ResponseEntity<OpenLmisResponse> response = baseController.handleException(new Exception()); final OpenLmisResponse body = response.getBody(); assertThat(body.getErrorMsg(), is("Oops, something has gone wrong. Please try again later")); }
@ExceptionHandler(Exception.class) public ResponseEntity<OpenLmisResponse> handleException(Exception ex) { logger.error("something broke with following exception... ", ex); if (ex instanceof AccessDeniedException) { return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN); } return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR); }
BaseController { @ExceptionHandler(Exception.class) public ResponseEntity<OpenLmisResponse> handleException(Exception ex) { logger.error("something broke with following exception... ", ex); if (ex instanceof AccessDeniedException) { return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN); } return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR); } }
BaseController { @ExceptionHandler(Exception.class) public ResponseEntity<OpenLmisResponse> handleException(Exception ex) { logger.error("something broke with following exception... ", ex); if (ex instanceof AccessDeniedException) { return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN); } return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR); }  }
BaseController { @ExceptionHandler(Exception.class) public ResponseEntity<OpenLmisResponse> handleException(Exception ex) { logger.error("something broke with following exception... ", ex); if (ex instanceof AccessDeniedException) { return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN); } return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR); }  @ExceptionHandler(Exception.class) ResponseEntity<OpenLmisResponse> handleException(Exception ex); }
BaseController { @ExceptionHandler(Exception.class) public ResponseEntity<OpenLmisResponse> handleException(Exception ex) { logger.error("something broke with following exception... ", ex); if (ex instanceof AccessDeniedException) { return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN); } return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR); }  @ExceptionHandler(Exception.class) ResponseEntity<OpenLmisResponse> handleException(Exception ex); static final String UNEXPECTED_EXCEPTION; static final String FORBIDDEN_EXCEPTION; static final String ACCEPT_JSON; static final String ACCEPT_PDF; static final String ACCEPT_CSV; @Autowired
  public MessageService messageService; }