-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.go
100 lines (88 loc) · 2.62 KB
/
errors.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package bingads
import (
"encoding/xml"
"fmt"
"strings"
)
type baseError struct {
code string
origErr error
}
func (b baseError) Error() string {
return b.origErr.Error()
}
func (b baseError) String() string {
return b.Error()
}
func (b baseError) Code() string {
return b.code
}
func (b baseError) OrigErr() error {
return b.origErr
}
type AdApiError struct {
Code int64 `xml:"AdApiError>Code"`
Details string `xml:"AdApiError>Details"`
ErrorCode string `xml:"AdApiError>ErrorCode"`
Message string `xml:"AdApiError>Message"`
}
type EditorialError struct {
Appealable bool `xml:"EditorialError>Appealable"`
Code int64 `xml:"EditorialError>Code"`
DisapprovedText string `xml:"EditorialError>DisapprovedText"`
ErrorCode string `xml:"EditorialError>ErrorCode"`
Index int64 `xml:"EditorialError>Index"`
Message string `xml:"EditorialError>Message"`
PublisherCountry string `xml:"EditorialError>PublisherCountry"`
}
type GoalError struct {
BatchErrors []BatchError `xml:"GoalError>BatchErrors"`
Index int64 `xml:"GoalError>Index"`
StepErrors []BatchError `xml:"GoalError>StepErrors"`
}
type OperationError struct {
Code int64 `xml:"OperationError>Code"`
Details string `xml:"OperationError>Details"`
ErrorCode string `xml:"OperationError>ErrorCode"`
Message string `xml:"OperationError>Message"`
}
type Fault struct {
FaultCode string `xml:"faultcode"`
FaultString string `xml:"faultstring"`
Detail struct {
XMLName xml.Name `xml:"detail"`
Errors ErrorsType `xml:",any"`
}
}
type ErrorsType struct {
TrackingId string `xml:"TrackingId"`
AdApiErrors []AdApiError `xml:"Errors"`
BatchErrors []BatchError `xml:"BatchErrors"`
EditorialErrors []EditorialError `xml:"EditorialErrors"`
GoalErrors []GoalError `xml:"GoalErrors"`
OperationErrors []OperationError `xml:"OperationErrors"`
}
func (f *ErrorsType) Error() string {
errors := []string{}
for _, e := range f.AdApiErrors {
errors = append(errors, fmt.Sprintf("%s", e.Message))
}
for _, e := range f.BatchErrors {
errors = append(errors, fmt.Sprintf("%s", e.Message))
}
for _, e := range f.EditorialErrors {
errors = append(errors, fmt.Sprintf("%s", e.Message))
}
for _, e := range f.GoalErrors {
for _, be := range e.BatchErrors {
errors = append(errors, fmt.Sprintf("%s", be.Message))
}
for _, be := range e.StepErrors {
errors = append(errors, fmt.Sprintf("%s", be.Message))
}
}
for _, e := range f.OperationErrors {
errors = append(errors, fmt.Sprintf("%s", e.Message))
}
return strings.Join(errors, "\n")
}