mardi 9 août 2016

How to handle Exception occuring when returning StreamingResponseBody from RestController

I have implemented a Spring Rest Controller that streams back large files using the StreamingResponseBody. However, these files are coming from another system and there is the potential for something to go wrong while streaming them back. When this occurs I am throwing a custom Exception (MyException). I am handling the exception in an @ExceptionHandler implementation which is below. I am attempting to set the response httpstatus and error message but I am always receiving http status 406. What is the proper way to handle errors/exceptions while returning a StreamingResponseBody?

@ExceptionHandler(MyException.class)
    public void handleParsException( MyException exception, HttpServletResponse response) throws IOException
    {
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(),exception.getMessage());
    }




Aucun commentaire:

Enregistrer un commentaire