Document whether code can rely on specific subclasses of HttpClientErrorException/HttpServerErrorException being thrown from DefaultResponseErrorHandler #25067
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: documentation
A documentation task
Milestone
From perusing the code, I discovered that
DefaultResponseErrorHandler
will throw subclasses ofHttpClientErrorException
/HttpServerErrorException
, created byHttpClientErrorException.create()
/HttpServerErrorException.create()
. For instance, if the request returned a 404 error, aHttpClientErrorException.NotFound
exception will be thrown.That said, I don't see any documentation indicating that the subclass is what will be thrown, rather than a the superclass
HttpClientErrorException
. I assume that it is intended that I can rely on this subclass being thrown, so I can write code like the following:instead of the clunkier:
It would be useful if it were documented that a consumer of the
RestTemplate
/DefaultResponseErrorHandler
can rely on these specific subclasses being thrown. This documentation could live in either or both theDefaultResponseErrorHandler
Javadocs or the general Spring documentation.The closest the current documentation comes to this is in the method Javadocs for
DefaultResponseErrorHandler.handleError(response, statusCode)
. But all that states is that it will throwHttpClientErrorException
orHttpServerErrorException
, not that it will throw the appropriate subclass if it exists. It has a "See also" section to the code that creates the subclasses, but that doesn't tell the user that it will be calling that, merely that the given code is related in some way.The text was updated successfully, but these errors were encountered: