-
Notifications
You must be signed in to change notification settings - Fork 0
/
v3_unexpected_response_error.go
44 lines (35 loc) · 1.02 KB
/
v3_unexpected_response_error.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 ccerror
import (
"fmt"
"strings"
)
// V3ErrorResponse represents a generic Cloud Controller V3 error response.
type V3ErrorResponse struct {
Errors []V3Error `json:"errors"`
}
// V3Error represents a cloud controller error.
type V3Error struct {
Code int `json:"code"`
Detail string `json:"detail"`
Title string `json:"title"`
}
// V3UnexpectedResponseError is returned when the client gets an error that has
// not been accounted for.
type V3UnexpectedResponseError struct {
V3ErrorResponse
ResponseCode int
RequestIDs []string
}
func (e V3UnexpectedResponseError) Error() string {
messages := []string{
"Unexpected Response",
fmt.Sprintf("Response Code: %d", e.ResponseCode),
}
for _, id := range e.RequestIDs {
messages = append(messages, fmt.Sprintf("Request ID: %s", id))
}
for _, ccError := range e.V3ErrorResponse.Errors {
messages = append(messages, fmt.Sprintf("Code: %d, Title: %s, Detail: %s", ccError.Code, ccError.Title, ccError.Detail))
}
return strings.Join(messages, "\n")
}