I have such Exception handler in spring RestController.
@ExceptionHandler(AuthException.class)
public ResponseEntity<String> handleCustomException(AuthException ex, Writer writer) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
ResponseEntity responseEntity = new ResponseEntity(headers, HttpStatus.FORBIDDEN);
(new ObjectMapper()).writeValue(writer, ex.getAsMap());
return responseEntity;
}
I expect result: Content-type: application-json Status: 403 And body:
{"date":"06-06-2019 18:36:34","errorCode":"102","error":"Login or password is not right","message":"Access denied"}
But result is: Status: 200 and Content-type is not set. Any suggestions?