Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3686

Spring ResponseStatusException does not return reason

$
0
0

I have a very simple @RestController, and I'm trying to set a custom error message. But for some reason, the message for the error is not showing up.

This is my controller:

@RestController@RequestMapping("openPharmacy")public class OpenPharmacyController {    @PostMapping    public String findNumberOfSurgeries(@RequestBody String skuLockRequest) {        throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "This postcode is not valid");    }}

This is the response that I get:

{"timestamp": "2020-06-24T17:44:20.194+00:00","status": 400,"error": "Bad Request","message": "","path": "/openPharmacy/"}

I'm passing a JSON, but I'm not validating anything, I'm just trying to set the custom message. If I change the status code, I see that on the response, but the message is always empty.

Why is this not working like expected? This is such a simple example that I can't see what may be missing. When I debug the code I can see that the error message has all the fields set. But for some reason, the message is never set on the response.


Viewing all articles
Browse latest Browse all 3686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>