spring-hateoas
spring-hateoas copied to clipboard
Added VndErrorException
Hi,
Some time ago I had created this little thingy for handling the VndErrors in Feign calls over SpringCloud: https://github.com/jmnarloch/feign-vnderror-spring-cloud-starter. I though that I would be better if there would be a unified exception that could be handled by multiple clients: Feign, RestTemplate, HttpClient, OkHttp etc. So I would like to propose adding one.
cc @olivergierke
What would that exception be used like? Would you mind adding test cases for the code you added? I guess we need to give the VndErrors implementation a bit of a rewrite anyway as it seems like the spec has moved significantly in the meantime.
So the whole idea is that this introduces a specialized version of HttpStatusCodeException that brings the payload information in a form of VndErrors, I am not expecting anything more that the Spring HATEOAS would just define it. This opens possibilities to try to unify the errors handling using different clients API like already mentioned: RestTemplate, AsyncRestTemplate and for instance Feign clients, but the integration would have be handled elsewhere. This would bring at least the common error representation.
So to clarify I can imagine to be able to process the errors as fallows:
try {
feignClient.getInvoices();
} catch (VndErrorException exc) {
...
}
with similar case with for instance RestTemplate:
try {
restOperations.postForObject(...);
} catch (VndErrorException exc) {
...
}
Simply by registering ResponseErrorHandler or ResponseDecoder in case of Feign.
I like the idea but could you explain how you avoid that the libraries you mentioned (Feign, RestTemplate, HttpClient, OkHttp etc.) need to have a dependency to the artifact which contains VndErrorException i.e. speing-hateoas?
Probably we can not avoid that, I made the PR here were the VndErrors is already being defined, though I would consider whether it wouldn't make more sense to move the VndErrors to spring-web at some point.
@olivergierke Thanks, for your thoughts. I've added extra tests, if you want to I can take a look at updating the implementation and align the VndErrors with the current specs, though I would rather prepare separate PR for that.
Also I was wondering way the exception hasn't been introduced in first place, the spring-web has this hall hierarchy of RestClientException.
@jmnarloch Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
@jmnarloch Thank you for signing the Contributor License Agreement!