Merge pull request #1693 from runcom/too-many-requests
registry: type too many requests error
This commit is contained in:
commit
d4be7016ef
@ -63,6 +63,16 @@ var (
|
|||||||
Description: "Returned when a service is not available",
|
Description: "Returned when a service is not available",
|
||||||
HTTPStatusCode: http.StatusServiceUnavailable,
|
HTTPStatusCode: http.StatusServiceUnavailable,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ErrorCodeTooManyRequests is returned if a client attempts too many
|
||||||
|
// times to contact a service endpoint.
|
||||||
|
ErrorCodeTooManyRequests = Register("errcode", ErrorDescriptor{
|
||||||
|
Value: "TOOMANYREQUESTS",
|
||||||
|
Message: "too many requests",
|
||||||
|
Description: `Returned when a client attempts to contact a
|
||||||
|
service too many times`,
|
||||||
|
HTTPStatusCode: http.StatusTooManyRequests,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
var nextCode = 1000
|
var nextCode = 1000
|
||||||
|
@ -51,11 +51,15 @@ func parseHTTPErrorResponse(statusCode int, r io.Reader) error {
|
|||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &detailsErr)
|
err = json.Unmarshal(body, &detailsErr)
|
||||||
if err == nil && detailsErr.Details != "" {
|
if err == nil && detailsErr.Details != "" {
|
||||||
if statusCode == http.StatusUnauthorized {
|
switch statusCode {
|
||||||
|
case http.StatusUnauthorized:
|
||||||
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
|
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
|
||||||
}
|
case http.StatusTooManyRequests:
|
||||||
|
return errcode.ErrorCodeTooManyRequests.WithMessage(detailsErr.Details)
|
||||||
|
default:
|
||||||
return errcode.ErrorCodeUnknown.WithMessage(detailsErr.Details)
|
return errcode.ErrorCodeUnknown.WithMessage(detailsErr.Details)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &errors); err != nil {
|
if err := json.Unmarshal(body, &errors); err != nil {
|
||||||
return &UnexpectedHTTPResponseError{
|
return &UnexpectedHTTPResponseError{
|
||||||
|
Loading…
Reference in New Issue
Block a user