@Test public void shouldRespondWithErrorContentAsJson() { final MarqetaError exception = new MarqetaError(); exception.setStatusCode(HttpStatus.BAD_REQUEST); exception.setErrorCode("400002"); exception.setErrorMessage("Birth date cannot be a future date"); final ResponseEntity<String> response = target.handleMarqetaError(exception); assertThat(response.getStatusCode(), is(equalTo(exception.getStatusCode()))); assertThat(response.getHeaders().getContentType(), is(equalTo(MediaType.APPLICATION_JSON))); assertThat(response.getBody(), is(equalTo(exception.getMessage()))); }
@ExceptionHandler(MarqetaError.class) public ResponseEntity<String> handleMarqetaError(MarqetaError exception) { logger.error("Handling Marqeta error:", exception); return ResponseEntity .status(exception.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .body(exception.getMessage()); }
MarqetaErrorControllerAdvice { @ExceptionHandler(MarqetaError.class) public ResponseEntity<String> handleMarqetaError(MarqetaError exception) { logger.error("Handling Marqeta error:", exception); return ResponseEntity .status(exception.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .body(exception.getMessage()); } }
MarqetaErrorControllerAdvice { @ExceptionHandler(MarqetaError.class) public ResponseEntity<String> handleMarqetaError(MarqetaError exception) { logger.error("Handling Marqeta error:", exception); return ResponseEntity .status(exception.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .body(exception.getMessage()); }  }
MarqetaErrorControllerAdvice { @ExceptionHandler(MarqetaError.class) public ResponseEntity<String> handleMarqetaError(MarqetaError exception) { logger.error("Handling Marqeta error:", exception); return ResponseEntity .status(exception.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .body(exception.getMessage()); }  @ExceptionHandler(MarqetaError.class) ResponseEntity<String> handleMarqetaError(MarqetaError exception); }
MarqetaErrorControllerAdvice { @ExceptionHandler(MarqetaError.class) public ResponseEntity<String> handleMarqetaError(MarqetaError exception) { logger.error("Handling Marqeta error:", exception); return ResponseEntity .status(exception.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .body(exception.getMessage()); }  @ExceptionHandler(MarqetaError.class) ResponseEntity<String> handleMarqetaError(MarqetaError exception);  }