spring-hateoas icon indicating copy to clipboard operation
spring-hateoas copied to clipboard

Added VndErrorException

Open jmnarloch opened this issue 10 years ago • 8 comments
trafficstars

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.

jmnarloch avatar Oct 10 '15 12:10 jmnarloch

cc @olivergierke

jmnarloch avatar Oct 22 '15 07:10 jmnarloch

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.

odrotbohm avatar Jan 13 '16 17:01 odrotbohm

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.

jmnarloch avatar Jan 13 '16 23:01 jmnarloch

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?

aheusingfeld avatar Jan 14 '16 07:01 aheusingfeld

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.

jmnarloch avatar Jan 14 '16 08:01 jmnarloch

@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 avatar Jan 17 '16 21:01 jmnarloch

@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.

pivotal-issuemaster avatar Dec 17 '18 18:12 pivotal-issuemaster

@jmnarloch Thank you for signing the Contributor License Agreement!

pivotal-issuemaster avatar Apr 07 '21 18:04 pivotal-issuemaster