-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
80 lines (65 loc) · 1.86 KB
/
errors.go
File metadata and controls
80 lines (65 loc) · 1.86 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
// Copyright 2017-2026 Allow2 Pty Ltd. All rights reserved.
// Use of this source code is governed by the Allow2 API and SDK Licence.
package allow2service
import "fmt"
// Allow2Error is the base error for all Allow2 SDK errors.
type Allow2Error struct {
Message string
Context map[string]interface{}
}
func (e *Allow2Error) Error() string {
return e.Message
}
// ApiError is thrown when an Allow2 API call fails with an unexpected error.
type ApiError struct {
Allow2Error
HTTPStatusCode int
ResponseBody map[string]interface{}
}
func (e *ApiError) Error() string {
if e.HTTPStatusCode > 0 {
return fmt.Sprintf("%s (HTTP %d)", e.Message, e.HTTPStatusCode)
}
return e.Message
}
// Unwrap returns the underlying Allow2Error.
func (e *ApiError) Unwrap() error {
return &e.Allow2Error
}
// TokenExpiredError is thrown when the OAuth2 token refresh fails
// and no valid token is available.
type TokenExpiredError struct {
Allow2Error
UserID string
}
func (e *TokenExpiredError) Error() string {
return e.Message
}
// Unwrap returns the underlying Allow2Error.
func (e *TokenExpiredError) Unwrap() error {
return &e.Allow2Error
}
// GetUserID returns the user ID associated with this error.
func (e *TokenExpiredError) GetUserID() string {
return e.UserID
}
// UnpairedError is thrown when the service account is no longer linked (HTTP 401/403 from API).
// The integration should redirect the user through OAuth2 re-pairing.
type UnpairedError struct {
Allow2Error
UserID string
}
func (e *UnpairedError) Error() string {
if e.Message != "" {
return e.Message
}
return "Service account is no longer linked. Re-pairing required."
}
// Unwrap returns the underlying Allow2Error.
func (e *UnpairedError) Unwrap() error {
return &e.Allow2Error
}
// GetUserID returns the user ID associated with this error.
func (e *UnpairedError) GetUserID() string {
return e.UserID
}