Created
September 28, 2016 18:15
-
-
Save seh/e13e879f762efaaa8dabff3ee7e5bdcb to your computer and use it in GitHub Desktop.
Helper functions for interpreting fargo errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fargo | |
import ( | |
"net/http" | |
"github.com/hudl/fargo" | |
) | |
// errorBoreHTTPStatusCode returns true if the supplied error originated from an HTTP response | |
// bearing the given HTTP status code. | |
func errorBoreHTTPStatusCode(err error, code int) bool { | |
c, ok := fargo.HTTPResponseStatusCode(err) | |
return ok && c == code | |
} | |
// eurekaThoughtInstanceWasInvalid returns true if the error arose during an instance registration | |
// attempt due to Eureka rejecting the proposed instance as invalid. | |
func eurekaThoughtInstanceWasInvalid(err error) bool { | |
return errorBoreHTTPStatusCode(err, http.StatusBadRequest) | |
} | |
// instanceWasMissing returns true if the error arose during an instance retrieval, status update, | |
// lease renewal, or deregistration attempt due to the target instance not being registered, being | |
// unknown to Eureka. | |
// | |
// See instanceWasMissingForMetadataUpdate to assess failures arising during metadata update attempts. | |
func instanceWasMissing(err error) bool { | |
return errorBoreHTTPStatusCode(err, http.StatusNotFound) | |
} | |
// instanceWasMissingForMetadataUpdate returns true if the error arose during a metadata update | |
// attempt due to the target instance not being registered, being unknown to Eureka. | |
// | |
// See instanceWasMissing to assess failures arising during instance retrieval, status update, | |
// lease renewal, or deregistration attempts. | |
func instanceWasMissingForMetadataUpdate(err error) bool { | |
return errorBoreHTTPStatusCode(err, http.StatusInternalServerError) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These functions are a caller-side adaptation of an earlier proposal for the fargo library itself (hudl/fargo#47), part of which made it into hudl/fargo#52.