-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ease interpretation of errors by HTTP status code #47
Conversation
For various operations involving HTTP requests against the Eureka server, allow callers to interpret surfaced failures by way of predicate functions. These predicates address the following operations: |--------------------------+----------+----------| | operation | missing? | invalid? | |--------------------------+----------+----------| | register instance | | ✓ | | reregister instance | | ✓ | | deregister instance | ✓ | | | update instance metadata | ✓ | | | update instance status | ✓ | | | renew instance lease | ✓ | | | retrieve instance | ✓ | | |--------------------------+----------+----------| Note that attempted instance metadata updates against an instance unknown by the server provoke an HTTP response with status code 500 rather than the 404 code used for similar responses for other operations.
Per the Eureka documentation and the implementation in method com.netflix.eureka.resources.InstanceResource#cancelLease(), Eureka returns HTTP status code 200 to indicate successful deregistration of an instance, and not status code 204 as our EurekaConnection's DeregisterInstance method had expected.
dee3433
to
2a4039d
Compare
Hey @seh In terms of error handling I think your solution is really clever, but to be honest I don't think it should be in fargo. Frankly speaking I like your workaround more then implementing this on a fargo side. We want to keep fargo as small and simple as possible. I would leave interpretation of error codes to the client app.
Please let me know what you think. (Also if you want to change Deregistration return code only feel free to open another pull request with that change so we can merge it). Thanks! |
I appreciate your thoughtful reply. First, let me submit a separate PR for just the deregistration status code, and then I'll come back to this discussion. |
Please see #48 for the deregistration status code portion of the proposal. |
For your second idea ( Would you be amenable to function like the following? // HTTPResponseStatusCode extracts the HTTP status code for the response from Eureka
// that motivated the supplied error, if any. If the returned present value is true, the returned
// code is an HTTP status code.
func HTTPResponseStatusCode(err error) (code int, present bool) With that, a caller could try something like if err := e.HeartBeatInstance(instance); err != nil {
if code, ok := fargo.HTTPResponseStatusCode(err); ok {
switch code {
case http.StatusNotFound:
// React to the instance being gone.
default:
// React to other codes.
}
}
// Handle errors that preceded receiving an HTTP response.
} I'd implement that function similarly to how I implemented the first pass at this proposal: return a private struct that implements I suspect that this solution would be more to your liking, as it keeps some of the situational interpretation out of fargo—even though fargo's method do contain some crude interpretation of which responses indicate success versus failure. |
For my idea: With your soulution, I like that approach more. As long as you can make it backwards compatible, so if someone were parsing error message as it is now then it should still work. I feel that overriding Please let me know what you think. Thank you! |
It's possible to implement I've adapted this proposal, whittling it down, but I still need to revise the tests. I'll aim to post it as a fresh pull request tomorrow. |
I'll abandon this proposal in favor of #52. |
Addressing #45, define two exported predicate functions to discern common reasons for instance-related operation failures.
Also, correct the expected HTTP status code in successful responses to deregistration requests.
Compare this branch against the earlier #46, which this one supersedes. In #46, I had used separate error types for each of the attempted HTTP operations. Here, instead, I used a single error type with an enumeration for the attempted HTTP operation, which I found made for more compact initializer expressions.