-
Notifications
You must be signed in to change notification settings - Fork 13
/
errors.go
99 lines (79 loc) · 1.66 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
package v1
import (
"fmt"
"html/template"
"strings"
apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
)
// Errors -
type Errors []apiv1.Error
// Error -
func (e Errors) Error() string {
b := &strings.Builder{}
b.WriteRune('[')
for i, err := range e {
b.WriteString(fmt.Sprintf("{\"status\": %d, \"detail\": \"%s\"}", err.Status, template.JSEscapeString(err.Detail)))
if i < len(e)-1 {
b.WriteRune(',')
}
}
b.WriteRune(']')
return b.String()
}
// ConflictError -
type ConflictError struct {
Errors
}
// Error -
func (nf ConflictError) Error() string {
return fmt.Sprintf("conflict: %s", nf.Errors)
}
// NotFoundError -
type NotFoundError struct {
Errors
}
// Error -
func (nf NotFoundError) Error() string {
return fmt.Sprintf("not found: %s", nf.Errors)
}
// InternalServerError -
type InternalServerError struct {
Errors
}
// Error -
func (nf InternalServerError) Error() string {
return fmt.Sprintf("internal server error: %s", nf.Errors)
}
// ForbiddenError -
type ForbiddenError struct {
Errors
}
// Error -
func (nf ForbiddenError) Error() string {
return fmt.Sprintf("forbidden: %s", nf.Errors)
}
// UnauthorizedError -
type UnauthorizedError struct {
Errors
}
// Error -
func (nf UnauthorizedError) Error() string {
return fmt.Sprintf("unauthorized: %s", nf.Errors)
}
// BadRequestError -
type BadRequestError struct {
Errors
}
// Error -
func (nf BadRequestError) Error() string {
return fmt.Sprintf("bad request: %s", nf.Errors)
}
// UnexpectedError -
type UnexpectedError struct {
code int
Errors
}
// Error -
func (nf UnexpectedError) Error() string {
return fmt.Sprintf("unexpected code %d: %s", nf.code, nf.Errors)
}