forked from nimajalali/go-force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
59 lines (47 loc) · 1.38 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
52
53
54
55
56
57
58
59
package force
import (
"fmt"
"strings"
)
// Custom Error to handle salesforce api responses.
type ApiErrors []*ApiError
type ApiError struct {
Fields []string `json:"fields,omitempty" force:"fields,omitempty"`
Message string `json:"message,omitempty" force:"message,omitempty"`
ErrorCode string `json:"errorCode,omitempty" force:"errorCode,omitempty"`
ErrorName string `json:"error,omitempty" force:"error,omitempty"`
ErrorDescription string `json:"error_description,omitempty" force:"error_description,omitempty"`
}
func (e ApiErrors) Error() string {
return e.String()
}
func (e ApiErrors) String() string {
s := make([]string, len(e))
for i, err := range e {
s[i] = err.String()
}
return strings.Join(s, "\n")
}
func (e ApiErrors) Validate() bool {
if len(e) != 0 {
return true
}
return false
}
func (e ApiError) Error() string {
return e.String()
}
func (e ApiError) String() string {
var fields string
if e.Fields != nil {
fields = strings.Join(e.Fields, ",")
}
return fmt.Sprintf("Fields: %v | Message: %v | ErrorCode: %v | ErrorName: %v | ErrorDescription: %v",
fields, e.Message, e.ErrorCode, e.ErrorName, e.ErrorDescription)
}
func (e ApiError) Validate() bool {
if len(e.Fields) != 0 || len(e.Message) != 0 || len(e.ErrorCode) != 0 || len(e.ErrorName) != 0 || len(e.ErrorDescription) != 0 {
return true
}
return false
}