2
I am using Swagger to get response of PUT() method. I have created a filter to limit request body size to 10000kb in my Spring boot Application. When I send request os size greater than 10000kb, i get swagger response as below.
Response Body :"no content" 
Response code: 500

I referred below link Spring boot Embedded Tomcat "application/json" post request restriction to 10KB

I used below to register the filter..

@Bean
    public FilterRegistrationBean loginRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new ApplicationJsonRequestSizeLimitFilter());
        filterRegistrationBean.setUrlPatterns(Collections.singletonList("/*"));
        return filterRegistrationBean;
}

How can i get status code, and custom message thrown by filter in response body.

1 Answers1

0

You should try the @ControllerAdvice

Here is an example how that would look like.

@ControllerAdvice
public class GlobalExceptionResolver{

@ResponseStatus(HttpStatus.BAD_REQUEST, reason = "Invalid request type")
@ExceptionHandler(value = SomeException.class)
public ResponseEntity<CustomError> handleSomeException(HttpServletRequest request, SomeException e){
    CustomError error = new CustomError();
    error.setMessage("Very large file");
    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(error);
}
}