Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
90 lines (74 loc) · 3.16 KB
/
Copy patherrors.go
File metadata and controls
90 lines (74 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package glassnode
import (
"errors"
"fmt"
"time"
)
// APIError describes a non-2xx response. Detail is bounded and credential-redacted.
// RetryAfter is how long the server asked the client to wait, taken from the
// Retry-After header or, for 429 responses, from x-rate-limit-reset. It is zero
// when the server gave no such hint.
type APIError struct {
StatusCode int
Endpoint string
Detail string
RetryAfter time.Duration
}
func (e *APIError) Error() string {
message := fmt.Sprintf("glassnode: %s: HTTP %d", e.Endpoint, e.StatusCode)
if e.Detail != "" {
message += ": " + e.Detail
}
return message
}
// Retryable reports whether this status is eligible for a GET retry.
func (e *APIError) Retryable() bool {
return e.StatusCode == 429 || e.StatusCode >= 500 && e.StatusCode <= 599
}
// ErrResponseTooLarge is the cause of every ResponseTooLargeError, for
// errors.Is.
var ErrResponseTooLarge = errors.New("response exceeds the configured size limit")
// ResponseTooLargeError reports a successful response whose body exceeds the
// WithMaxResponseBytes limit. It is a decision of the client's configuration,
// not a transport or decoding failure, and the call is not retried.
type ResponseTooLargeError struct {
Endpoint string
Limit int64
}
func (e *ResponseTooLargeError) Error() string {
return fmt.Sprintf("glassnode: %s: response exceeds the configured limit of %d bytes", e.Endpoint, e.Limit)
}
// Unwrap returns ErrResponseTooLarge.
func (e *ResponseTooLargeError) Unwrap() error { return ErrResponseTooLarge }
// InputError describes invalid configuration or arguments, before any request.
type InputError struct{ Field, Message string }
func (e *InputError) Error() string { return "glassnode: " + e.Field + ": " + e.Message }
// DecodeError describes a response that does not match the destination Go type.
// It is never retried. SDK-generated messages redact credentials, including
// custom decoder errors. Unwrap exposes the original error for inspection.
type DecodeError struct {
Endpoint string
Err error
}
func (e *DecodeError) Error() string {
return "glassnode: decoding " + e.Endpoint + " response: " + e.Err.Error()
}
func (e *DecodeError) Unwrap() error { return e.Err }
// TransportError describes a failure in transit. SDK-generated error messages
// include the credential-redacted cause. Unwrap retains the original cause.
// The cause may contain credentials and should not be logged indiscriminately.
type TransportError struct {
Endpoint string
Err error
}
func (e *TransportError) Error() string {
return "glassnode: request failed for " + e.Endpoint + ": " + e.Err.Error()
}
func (e *TransportError) Unwrap() error { return e.Err }
// AuthError describes a token-source failure or an invalid token. It is never
// retried. Messages redact credentials used in the call; the token source must
// avoid returning errors containing other credentials unknown to the SDK.
// Unwrapped causes may contain secrets and should not be logged indiscriminately.
type AuthError struct{ Err error }
func (e *AuthError) Error() string { return "glassnode: acquiring bearer token: " + e.Err.Error() }
func (e *AuthError) Unwrap() error { return e.Err }