forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
44 lines (38 loc) · 1.4 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
package errors
import (
"encoding/json"
"fmt"
"github.com/gophercloud/gophercloud"
)
type ManilaError struct {
Code int `json:"code"`
Message string `json:"message"`
Details string `json:"details"`
}
type ErrorDetails map[string]ManilaError
// error types from provider_client.go
func ExtractErrorInto(rawError error, errorDetails *ErrorDetails) (err error) {
switch e := rawError.(type) {
case gophercloud.ErrDefault400:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault401:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault403:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault404:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault405:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault408:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault429:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault500:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
case gophercloud.ErrDefault503:
err = json.Unmarshal(e.ErrUnexpectedResponseCode.Body, errorDetails)
default:
err = fmt.Errorf("Unable to extract detailed error message")
}
return err
}