RequestExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(SmartCosmosException.class) protected ResponseEntity<?> handleSmartCosmosExceptionMethod(SmartCosmosException exception, WebRequest request) { if (exception.getCause() == null) { logException(exception, request); HttpHeaders headers = new HttpHeaders(); HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; return handleExceptionInternal(exception, getErrorResponseBody(ERR_FAILURE, exception.getMessage()), headers, status, request); } if (exception.getCause() instanceof NoEntityFoundException) { return handleNoEntityFoundRequestHandlingMethod((NoEntityFoundException) exception.getCause(), request); } if (exception.getCause() instanceof ConversionFailedException) { return handleConversionFailure((ConversionFailedException) exception.getCause(), request); } if (exception.getCause() instanceof IllegalArgumentException) { return handleIllegalArgument((IllegalArgumentException) exception.getCause(), request); } if (exception.getCause() instanceof ConstraintViolationException) { return handleConstraintViolation((ConstraintViolationException) exception.getCause(), request); } if (exception.getCause() instanceof HttpStatusCodeException) { return handleHttpStatusCodeException((HttpStatusCodeException) exception.getCause(), request); } if (exception.getCause() instanceof MethodArgumentNotValidException) { HttpHeaders headers = new HttpHeaders(); HttpStatus status = HttpStatus.BAD_REQUEST; return handleMethodArgumentNotValid((MethodArgumentNotValidException) exception.getCause(), headers, status, request); } HttpHeaders headers = new HttpHeaders(); HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; return handleExceptionInternal(exception, getErrorResponseBody(ERR_FAILURE, exception.toString()), headers, status, request); }   static final String DEFAULT_SMART_COSMOS_EXCEPTION_MESSAGE; }
@Test public void thatSmartCosmosExceptionWithNoCauseReturnsErrFailureResponseBody() { SmartCosmosException smartCosmosException = new SmartCosmosException("just message, no cause"); ResponseEntity responseEntity = handler.handleSmartCosmosExceptionMethod(smartCosmosException, webRequest); assertEquals(responseEntity.getStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR); assertEquals(((Map<String, String>)responseEntity.getBody()).get("message"), "just message, no cause"); }