...
1 package smithy
2
3 import "fmt"
4
5
6
7 type APIError interface {
8 error
9
10
11 ErrorCode() string
12
13 ErrorMessage() string
14
15 ErrorFault() ErrorFault
16 }
17
18
19
20
21 type GenericAPIError struct {
22 Code string
23 Message string
24 Fault ErrorFault
25 }
26
27
28 func (e *GenericAPIError) ErrorCode() string { return e.Code }
29
30
31 func (e *GenericAPIError) ErrorMessage() string { return e.Message }
32
33
34 func (e *GenericAPIError) ErrorFault() ErrorFault { return e.Fault }
35
36 func (e *GenericAPIError) Error() string {
37 return fmt.Sprintf("api error %s: %s", e.Code, e.Message)
38 }
39
40 var _ APIError = (*GenericAPIError)(nil)
41
42
43
44 type OperationError struct {
45 ServiceID string
46 OperationName string
47 Err error
48 }
49
50
51 func (e *OperationError) Service() string { return e.ServiceID }
52
53
54 func (e *OperationError) Operation() string { return e.OperationName }
55
56
57 func (e *OperationError) Unwrap() error { return e.Err }
58
59 func (e *OperationError) Error() string {
60 return fmt.Sprintf("operation error %s: %s, %v", e.ServiceID, e.OperationName, e.Err)
61 }
62
63
64
65 type DeserializationError struct {
66 Err error
67 Snapshot []byte
68 }
69
70
71 func (e *DeserializationError) Error() string {
72 const msg = "deserialization failed"
73 if e.Err == nil {
74 return msg
75 }
76 return fmt.Sprintf("%s, %v", msg, e.Err)
77 }
78
79
80 func (e *DeserializationError) Unwrap() error { return e.Err }
81
82
83 type ErrorFault int
84
85
86 const (
87 FaultUnknown ErrorFault = iota
88 FaultServer
89 FaultClient
90 )
91
92 func (f ErrorFault) String() string {
93 switch f {
94 case FaultServer:
95 return "server"
96 case FaultClient:
97 return "client"
98 default:
99 return "unknown"
100 }
101 }
102
103
104 type SerializationError struct {
105 Err error
106 }
107
108
109 func (e *SerializationError) Error() string {
110 const msg = "serialization failed"
111 if e.Err == nil {
112 return msg
113 }
114 return fmt.Sprintf("%s: %v", msg, e.Err)
115 }
116
117
118 func (e *SerializationError) Unwrap() error { return e.Err }
119
120
121
122
123 type CanceledError struct {
124 Err error
125 }
126
127
128 func (*CanceledError) CanceledError() bool { return true }
129
130
131 func (e *CanceledError) Unwrap() error {
132 return e.Err
133 }
134
135 func (e *CanceledError) Error() string {
136 return fmt.Sprintf("canceled, %v", e.Err)
137 }
138
View as plain text