blob: e47aff1ca002819f15aa90b39583c78a29d818e7 [file] [log] [blame]
jrperrittb1013232016-02-10 19:01:53 -06001package gophercloud
2
3import "fmt"
4
5// BaseError is an error type that all other error types embed.
6type BaseError struct {
7 OriginalError string
8 Function string
9}
10
11func (e *BaseError) Error() string {
12 return "An error occurred while executing a Gophercloud request."
13}
14
15// ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
16type ErrInvalidInput struct {
17 BaseError
18 Argument string
19 Value interface{}
20}
21
22func (e *ErrInvalidInput) Error() string {
23 return fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
24}
25
26// ErrUnexpectedResponseCode is returned by the Request method when a response code other than
27// those listed in OkCodes is encountered.
28type ErrUnexpectedResponseCode struct {
29 BaseError
30 URL string
31 Method string
32 Expected []int
33 Actual int
34 Body []byte
35}
36
37func (err *ErrUnexpectedResponseCode) Error() string {
38 return fmt.Sprintf(
39 "Expected HTTP response code %v when accessing [%s %s], but got %d instead\n%s",
40 err.Expected, err.Method, err.URL, err.Actual, err.Body,
41 )
42}
43
44type ErrDefault400 struct {
45 *ErrUnexpectedResponseCode
46}
47type ErrDefault401 struct {
48 *ErrUnexpectedResponseCode
49}
50type ErrDefault404 struct {
51 *ErrUnexpectedResponseCode
52}
53type ErrDefault405 struct {
54 *ErrUnexpectedResponseCode
55}
56type ErrDefault408 struct {
57 *ErrUnexpectedResponseCode
58}
59type ErrDefault429 struct {
60 *ErrUnexpectedResponseCode
61}
62type ErrDefault500 struct {
63 *ErrUnexpectedResponseCode
64}
65type ErrDefault503 struct {
66 *ErrUnexpectedResponseCode
67}
68
69func (e ErrDefault400) Error() string {
70 return "Invalid request due to incorrect syntax or missing required parameters."
71}
72func (e ErrDefault401) Error() string {
73 return "Authentication failed"
74}
75func (e ErrDefault404) Error() string {
76 return "Resource not found"
77}
78func (e ErrDefault405) Error() string {
79 return "Method not allowed"
80}
81func (e ErrDefault408) Error() string {
82 return "The server timed out waiting for the request"
83}
84func (e ErrDefault429) Error() string {
85 return "Too many requests have been sent in a given amount of time. Pause requests, wait up to one minute, and try again."
86}
87func (e ErrDefault500) Error() string {
88 return "Internal Server Error"
89}
90func (e ErrDefault503) Error() string {
91 return "The service is currently unable to handle the request due to a temporary overloading or maintenance. This is a temporary condition. Try again later."
92}
93
94// Err400er is the interface resource error types implement to override the error message
95// from a 400 error.
96type Err400er interface {
97 Error400(*ErrUnexpectedResponseCode) error
98}
99
100// Err401er is the interface resource error types implement to override the error message
101// from a 401 error.
102type Err401er interface {
103 Error401(*ErrUnexpectedResponseCode) error
104}
105
106// Err404er is the interface resource error types implement to override the error message
107// from a 404 error.
108type Err404er interface {
109 Error404(*ErrUnexpectedResponseCode) error
110}
111
112// Err405er is the interface resource error types implement to override the error message
113// from a 405 error.
114type Err405er interface {
115 Error405(*ErrUnexpectedResponseCode) error
116}
117
118// Err408er is the interface resource error types implement to override the error message
119// from a 408 error.
120type Err408er interface {
121 Error408(*ErrUnexpectedResponseCode) error
122}
123
124// Err429er is the interface resource error types implement to override the error message
125// from a 429 error.
126type Err429er interface {
127 Error429(*ErrUnexpectedResponseCode) error
128}
129
130// Err500er is the interface resource error types implement to override the error message
131// from a 500 error.
132type Err500er interface {
133 Error500(*ErrUnexpectedResponseCode) error
134}
135
136// Err503er is the interface resource error types implement to override the error message
137// from a 503 error.
138type Err503er interface {
139 Error503(*ErrUnexpectedResponseCode) error
140}
141
142type ErrTimeOut struct {
143 *BaseError
144}
145
146func (e *ErrTimeOut) Error() string {
147 return "A time out occurred"
148}
149
150type ErrUnableToReauthenticate struct {
151 *BaseError
152}
153
154func (e *ErrUnableToReauthenticate) Error() string {
155 return fmt.Sprintf("Unable to re-authenticate: %s", e.OriginalError)
156}
157
158type ErrErrorAfterReauthentication struct {
159 *BaseError
160}
161
162func (e *ErrErrorAfterReauthentication) Error() string {
163 return fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.OriginalError)
164}
165
166// ErrServiceNotFound is returned when no service in a service catalog matches
167// the provided EndpointOpts. This is generally returned by provider service
168// factory methods like "NewComputeV2()" and can mean that a service is not
169// enabled for your account.
170type ErrServiceNotFound struct {
171 *BaseError
172}
173
174func (e *ErrServiceNotFound) Error() string {
175 return "No suitable service could be found in the service catalog."
176}
177
178// ErrEndpointNotFound is returned when no available endpoints match the
179// provided EndpointOpts. This is also generally returned by provider service
180// factory methods, and usually indicates that a region was specified
181// incorrectly.
182type ErrEndpointNotFound struct {
183 *BaseError
184}
185
186func (e *ErrEndpointNotFound) Error() string {
187 return "No suitable endpoint could be found in the service catalog."
188}