Skip to content

Instantly share code, notes, and snippets.

@seh
Created Sep 28, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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