forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_error.go
63 lines (53 loc) · 1.04 KB
/
http_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package errors
import "fmt"
type HttpError interface {
Error
StatusCode() int
Headers() string
Body() string
}
type httpError struct {
statusCode int
headers string
body string
code string
description string
}
type HttpNotFoundError struct {
*httpError
}
func NewHttpError(statusCode int, header string, body string, code string, description string) HttpError {
err := httpError{
statusCode: statusCode,
headers: header,
body: body,
code: code,
description: description,
}
switch statusCode {
case 404:
return HttpNotFoundError{&err}
default:
return &err
}
}
func (err *httpError) StatusCode() int {
return err.statusCode
}
func (err *httpError) Headers() string {
return err.headers
}
func (err *httpError) Body() string {
return err.body
}
func (err *httpError) Error() string {
return fmt.Sprintf(
"Server error, status code: %d, error code: %s, message: %s",
err.statusCode,
err.code,
err.description,
)
}
func (err *httpError) ErrorCode() string {
return err.code
}