Skip to content

Instantly share code, notes, and snippets.

@seh
Created September 28, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seh/e13e879f762efaaa8dabff3ee7e5bdcb to your computer and use it in GitHub Desktop.
Save seh/e13e879f762efaaa8dabff3ee7e5bdcb to your computer and use it in GitHub Desktop.
Helper functions for interpreting fargo errors
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)
}
@seh
Copy link
Author

seh commented Sep 28, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment