-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
55 lines (43 loc) · 1.77 KB
/
Copy patherrors.go
File metadata and controls
55 lines (43 loc) · 1.77 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
package ramp
import (
"errors"
"github.com/iamkanishka/ramp-go/shared"
)
// Re-export error types from shared so callers only need one import.
// ErrorType classifies the category of a Ramp API error.
type ErrorType = shared.ErrorType
const (
ErrorTypeAuthentication = shared.ErrorTypeAuthentication
ErrorTypeAuthorization = shared.ErrorTypeAuthorization
ErrorTypeNotFound = shared.ErrorTypeNotFound
ErrorTypeValidation = shared.ErrorTypeValidation
ErrorTypeRateLimit = shared.ErrorTypeRateLimit
ErrorTypeServer = shared.ErrorTypeServer
ErrorTypeTimeout = shared.ErrorTypeTimeout
ErrorTypeNetwork = shared.ErrorTypeNetwork
ErrorTypeDeferred = shared.ErrorTypeDeferred
ErrorTypeUnknown = shared.ErrorTypeUnknown
)
// Error is the structured error type returned by all SDK operations.
type Error = shared.Error
// APIError constructs an Error from an HTTP response status and body.
func APIError(statusCode int, body []byte, traceID string) *Error {
return shared.APIError(statusCode, body, traceID)
}
// IsNotFound reports whether err is a Ramp 404 error.
func IsNotFound(err error) bool { return isType(err, ErrorTypeNotFound) }
// IsRateLimit reports whether err is a Ramp 429 rate-limit error.
func IsRateLimit(err error) bool { return isType(err, ErrorTypeRateLimit) }
// IsAuth reports whether err is a Ramp authentication or authorization error.
func IsAuth(err error) bool {
return isType(err, ErrorTypeAuthentication) || isType(err, ErrorTypeAuthorization)
}
// IsValidation reports whether err is a Ramp 400 validation error.
func IsValidation(err error) bool { return isType(err, ErrorTypeValidation) }
func isType(err error, t ErrorType) bool {
var re *Error
if errors.As(err, &re) {
return re.Type == t
}
return false
}