blob: 3de5363f0b24a682c20f3e1f67d5886d73cc3d13 [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 {
Jon Perritte0f9e4f2016-02-21 21:41:03 -06007 OriginalError error
jrperrittb1013232016-02-10 19:01:53 -06008 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 {
Jon Perritte0f9e4f2016-02-21 21:41:03 -060017 *BaseError
jrperrittb1013232016-02-10 19:01:53 -060018 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 {
Jon Perritte0f9e4f2016-02-21 21:41:03 -060029 *BaseError
jrperrittb1013232016-02-10 19:01:53 -060030 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
Jon Perritte0f9e4f2016-02-21 21:41:03 -060044// ErrDefault400 is the default error type returned on a 400 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060045type ErrDefault400 struct {
46 *ErrUnexpectedResponseCode
47}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060048
49// ErrDefault401 is the default error type returned on a 401 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060050type ErrDefault401 struct {
51 *ErrUnexpectedResponseCode
52}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060053
54// ErrDefault404 is the default error type returned on a 404 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060055type ErrDefault404 struct {
56 *ErrUnexpectedResponseCode
57}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060058
59// ErrDefault405 is the default error type returned on a 405 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060060type ErrDefault405 struct {
61 *ErrUnexpectedResponseCode
62}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060063
64// ErrDefault408 is the default error type returned on a 408 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060065type ErrDefault408 struct {
66 *ErrUnexpectedResponseCode
67}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060068
69// ErrDefault429 is the default error type returned on a 429 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060070type ErrDefault429 struct {
71 *ErrUnexpectedResponseCode
72}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060073
74// ErrDefault500 is the default error type returned on a 500 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060075type ErrDefault500 struct {
76 *ErrUnexpectedResponseCode
77}
Jon Perritte0f9e4f2016-02-21 21:41:03 -060078
79// ErrDefault503 is the default error type returned on a 503 HTTP response code.
jrperrittb1013232016-02-10 19:01:53 -060080type ErrDefault503 struct {
81 *ErrUnexpectedResponseCode
82}
83
84func (e ErrDefault400) Error() string {
85 return "Invalid request due to incorrect syntax or missing required parameters."
86}
87func (e ErrDefault401) Error() string {
88 return "Authentication failed"
89}
90func (e ErrDefault404) Error() string {
91 return "Resource not found"
92}
93func (e ErrDefault405) Error() string {
94 return "Method not allowed"
95}
96func (e ErrDefault408) Error() string {
97 return "The server timed out waiting for the request"
98}
99func (e ErrDefault429) Error() string {
100 return "Too many requests have been sent in a given amount of time. Pause requests, wait up to one minute, and try again."
101}
102func (e ErrDefault500) Error() string {
103 return "Internal Server Error"
104}
105func (e ErrDefault503) Error() string {
106 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."
107}
108
109// Err400er is the interface resource error types implement to override the error message
110// from a 400 error.
111type Err400er interface {
112 Error400(*ErrUnexpectedResponseCode) error
113}
114
115// Err401er is the interface resource error types implement to override the error message
116// from a 401 error.
117type Err401er interface {
118 Error401(*ErrUnexpectedResponseCode) error
119}
120
121// Err404er is the interface resource error types implement to override the error message
122// from a 404 error.
123type Err404er interface {
124 Error404(*ErrUnexpectedResponseCode) error
125}
126
127// Err405er is the interface resource error types implement to override the error message
128// from a 405 error.
129type Err405er interface {
130 Error405(*ErrUnexpectedResponseCode) error
131}
132
133// Err408er is the interface resource error types implement to override the error message
134// from a 408 error.
135type Err408er interface {
136 Error408(*ErrUnexpectedResponseCode) error
137}
138
139// Err429er is the interface resource error types implement to override the error message
140// from a 429 error.
141type Err429er interface {
142 Error429(*ErrUnexpectedResponseCode) error
143}
144
145// Err500er is the interface resource error types implement to override the error message
146// from a 500 error.
147type Err500er interface {
148 Error500(*ErrUnexpectedResponseCode) error
149}
150
151// Err503er is the interface resource error types implement to override the error message
152// from a 503 error.
153type Err503er interface {
154 Error503(*ErrUnexpectedResponseCode) error
155}
156
Jon Perritte0f9e4f2016-02-21 21:41:03 -0600157// ErrTimeOut is the error type returned when an operations times out.
jrperrittb1013232016-02-10 19:01:53 -0600158type ErrTimeOut struct {
159 *BaseError
160}
161
162func (e *ErrTimeOut) Error() string {
163 return "A time out occurred"
164}
165
Jon Perritte0f9e4f2016-02-21 21:41:03 -0600166// ErrUnableToReauthenticate is the error type returned when reauthentication fails.
jrperrittb1013232016-02-10 19:01:53 -0600167type ErrUnableToReauthenticate struct {
168 *BaseError
169}
170
171func (e *ErrUnableToReauthenticate) Error() string {
172 return fmt.Sprintf("Unable to re-authenticate: %s", e.OriginalError)
173}
174
Jon Perritte0f9e4f2016-02-21 21:41:03 -0600175// ErrErrorAfterReauthentication is the error type returned when reauthentication
176// succeeds, but an error occurs afterword (usually an HTTP error).
jrperrittb1013232016-02-10 19:01:53 -0600177type ErrErrorAfterReauthentication struct {
178 *BaseError
179}
180
181func (e *ErrErrorAfterReauthentication) Error() string {
182 return fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.OriginalError)
183}
184
185// ErrServiceNotFound is returned when no service in a service catalog matches
186// the provided EndpointOpts. This is generally returned by provider service
187// factory methods like "NewComputeV2()" and can mean that a service is not
188// enabled for your account.
189type ErrServiceNotFound struct {
190 *BaseError
191}
192
193func (e *ErrServiceNotFound) Error() string {
194 return "No suitable service could be found in the service catalog."
195}
196
197// ErrEndpointNotFound is returned when no available endpoints match the
198// provided EndpointOpts. This is also generally returned by provider service
199// factory methods, and usually indicates that a region was specified
200// incorrectly.
201type ErrEndpointNotFound struct {
202 *BaseError
203}
204
205func (e *ErrEndpointNotFound) Error() string {
206 return "No suitable endpoint could be found in the service catalog."
207}