-
Notifications
You must be signed in to change notification settings - Fork 28
/
error.go
51 lines (43 loc) · 1.72 KB
/
error.go
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
package hubspot
import "fmt"
const (
// ValidationError is the APIError.Category.
// This is returned by HubSpot when the HTTP Status is 400.
// In this case, the verification details error will be included in Details
ValidationError = "VALIDATION_ERROR"
// InvalidEmailError is the value of ErrDetail.Error when an error occurs in the Email validation.
InvalidEmailError = "INVALID_EMAIL"
// UnknownDetailError is the value set by go-hubspot when extraction the error details failed.
UnknownDetailError = "UNKNOWN_DETAIL"
)
type APIError struct {
HTTPStatusCode int `json:"-"`
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
CorrelationID string `json:"correlationId,omitempty"`
Context ErrContext `json:"context,omitempty"`
Category string `json:"category,omitempty"`
SubCategory string `json:"subCategory,omitempty"`
Links ErrLinks `json:"links,omitempty"`
Details []ErrDetail `json:"details,omitempty"`
}
type ErrDetail struct {
IsValid bool `json:"isValid,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Name string `json:"name,omitempty"`
}
type ErrContext struct {
ID []string `json:"id,omitempty"`
Type []string `json:"type,omitempty"`
ObjectType []string `json:"objectType,omitempty"`
FromObjectType []string `json:"fromObjectType,omitempty"`
ToObjectType []string `json:"toObjectType,omitempty"`
}
type ErrLinks struct {
APIKey string `json:"api key,omitempty"`
KnowledgeBase string `json:"knowledge-base,omitempty"`
}
func (e APIError) Error() string {
return fmt.Sprintf("%d: %s", e.HTTPStatusCode, e.Message)
}