@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) public @ResponseBody BasicOutputDto unhandledError(HttpServletRequest req, Exception exception) { this.getOwnLogger() .error("Url: " + req.getRequestURL() + " raised: " + exception.getMessage(), exception); BasicOutputDto dto = new BasicOutputDto(BasicOutputType.UNHANDLED_ERROR.getId()); dto.setMessage("An unhandled error has ocurred on MYO."); dto.addCause(exception.getMessage()); return dto; }
@ResponseStatus(value = HttpStatus.BAD_REQUEST) @ExceptionHandler(IllegalArgumentException.class) public @ResponseBody BasicOutputDto illegalArgumentError( HttpServletRequest req, Exception exception) { this.getOwnLogger() .error("Url: " + req.getRequestURL() + " raised: " + exception.getMessage(), exception); BasicOutputDto dto = new BasicOutputDto(BasicOutputType.ILLEGAL_ARGUMENTS.getId()); dto.setMessage("Bad Request, illegal arguments received."); dto.addCause(exception.getMessage()); return dto; }
@ResponseStatus(value = HttpStatus.ACCEPTED) @ExceptionHandler(ConstraintViolationException.class) public @ResponseBody BasicOutputDto unhandledConstraintError( HttpServletRequest req, Exception exception) { ConstraintViolationException ce = (ConstraintViolationException) exception; this.getOwnLogger() .error( "Url: " + req.getRequestURL() + " raised: " + ce.getSQLException().getMessage(), exception); BasicOutputDto dto = new BasicOutputDto(BasicOutputType.SQL_CONSTRAINT_ERROR.getId()); dto.setMessage( String.format( "An unhandled constraint violation error has ocurred on MYO. SQLState: %s", ce.getSQLState())); dto.addCause(ce.getSQLException().getMessage()); return dto; }