-
Notifications
You must be signed in to change notification settings - Fork 18
/
unhandled.go
50 lines (43 loc) · 1.23 KB
/
unhandled.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
45
46
47
48
49
50
package errors
import (
"fmt"
"net/http"
)
// UnhandledResponseError stores information of an unhandled error response.
type UnhandledResponseError struct {
StatusCode int
Header http.Header
Content string
}
// Error returns the description of QingStor error response.
func (e UnhandledResponseError) Error() string {
return fmt.Sprintf(
"Unhandled Error: StatusCode \"%d\", Header \"%v\", Content \"%s\"",
e.StatusCode, e.Header, e.Content)
}
// NewUnhandledResponseError conduct an unhandled response error
func NewUnhandledResponseError(fs ...func(*UnhandledResponseError)) UnhandledResponseError {
e := UnhandledResponseError{}
for _, f := range fs {
f(&e)
}
return e
}
// WithStatusCode set StatusCode for UnhandledResponseError
func WithStatusCode(code int) func(*UnhandledResponseError) {
return func(e *UnhandledResponseError) {
e.StatusCode = code
}
}
// WithContent set Content for UnhandledResponseError
func WithContent(detail string) func(*UnhandledResponseError) {
return func(e *UnhandledResponseError) {
e.Content = detail
}
}
// WithHeader set Header for UnhandledResponseError
func WithHeader(h http.Header) func(*UnhandledResponseError) {
return func(e *UnhandledResponseError) {
e.Header = h
}
}