SERVER: Spring Frames
I have a Spring controller that has a method that returns a ResponseEntity<String> .
For perfectly good queries, I return the following:
return new ResponseEntity<>(OK_MESSAGE, new HttpHeaders(), HttpStatus.OK);
But if there are any problems at runtime or catching the Exception, I return:
return new ResponseEntity<>(ERROR_MESSAGE, new HttpHeaders(), HttpStatus.BAD_REQUEST);
Where ERROR_MESSAGE contains a custom string for each selected exception type.
CLIENT PARTY: AJAX challenge
When this POST method is called and returns HttpStatus.OK, AJAX
success: function (data, message, xhr)
and I can easily access String OK_MESSAGE by accessing data .
Problem is that the POST method returns HttpStatus.BAD_REQUEST, AJAX
error: function (xhr, status, errMsg)
Called
but I cannot access String ERROR_MESSAGE sent by the server that I need to show to the user.
Any suggestions?