Saturday, 15 March 2014

Modify default JSON error response from Spring Boot Rest Controller -


itemprop = "text">

Currently there is standard content in the error response from spring boot:

  { "" "1426615606," exception ":" org.springframework.web.bind.MissingServletRequestParameterException "," status ": 400," Error ":" Bad Request "," Path ":" / Welcome "," Message ": "Required string parameter 'name' does not exist)}  

I'm looking for a way to get rid of the" exception "property in the response. Is there any way to get it?

As described in, you can provide your own intake to take control of the material Error entries

An easy way to do this is by sub code DefaultErrorAttributes . For example:

  @bean public error character attribute property properties () (Return to new default error ({@ override public map & lt; string, object & gt; GetErrorAttributes (RequestAttributes request attributes, include Boolean StackTrace) {map & lt; string, object & gt; ErrorAttributes = super.getErrorAttributes (requestAttributes, StackTrace included); // Customize the default entries in the error entries that meet your needs. The return return property;}};}  

No comments:

Post a Comment