-
Notifications
You must be signed in to change notification settings - Fork 142
/
errors.go
44 lines (37 loc) 路 876 Bytes
/
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 svix
import (
"net/http"
"github.com/svix/svix-libs/go/internal/openapi"
)
// Error provides access to the body, status, and error on returned errors.
type Error struct {
status int
body []byte
error string
}
// Error returns non-empty string if there was an error.
func (e Error) Error() string {
return e.error
}
// Body returns the raw bytes of the response.
func (e Error) Body() []byte {
return e.body
}
// Status returns the HTTP status of the error.
func (e Error) Status() int {
return e.status
}
// a simple function convert openapi errors to exposed svix.Error
func wrapError(err error, res *http.Response) error {
if openapiError, ok := err.(openapi.GenericOpenAPIError); ok {
e := &Error{
body: openapiError.Body(),
error: openapiError.Error(),
}
if res != nil {
e.status = res.StatusCode
}
return e
}
return err
}