-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror.go
49 lines (39 loc) · 967 Bytes
/
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
package aandaSdk
import (
"errors"
"fmt"
"strings"
)
type AandaError struct {
Status string `json:"status" json:"Status"`
Code MustString `json:"code" json:"Code"`
Type string `json:"type" json:"Type"`
Note string `json:"note" json:"Note"`
}
func (o *AandaError) IsEmpty() bool {
return o.Status == "" && (o.Code == "" || o.Code == "0") && o.Type == "" && o.Note == ""
}
func (o *AandaError) ToError() error {
var msgs []string
for _, s := range []string{o.Type, o.Note} {
if s != "" {
msgs = append(msgs, s)
}
}
return errors.New(strings.Join(msgs, "; "))
}
func (o *AandaError) Error() string {
return fmt.Sprintf("[%s] %s - %s; %s", o.Status, o.Code, o.Type, o.Note)
}
type AandaErrorMsg struct {
Err string `json:"error"`
}
func (o *AandaErrorMsg) IsEmpty() bool {
return o.Err == ""
}
func (o *AandaErrorMsg) ToError() error {
return errors.New(o.Err)
}
func (o *AandaErrorMsg) Error() string {
return o.Err
}