-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
34 lines (30 loc) · 768 Bytes
/
error.go
File metadata and controls
34 lines (30 loc) · 768 Bytes
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
package mbz
import (
"fmt"
"io"
"net/http"
)
// ResponseError represents a VW Fleet Interface response error.
type ResponseError struct {
// StatusCode is the HTTP status code of the response.
StatusCode int
// Body is the body of the response.
Body []byte
}
func newResponseError(httpResponse *http.Response) error {
body, err := io.ReadAll(httpResponse.Body)
if err != nil {
body = fmt.Appendf(nil, "failed to read response body: %s", err)
}
return &ResponseError{
StatusCode: httpResponse.StatusCode,
Body: body,
}
}
// Error implements the error interface.
func (e *ResponseError) Error() string {
if len(e.Body) > 0 {
return fmt.Sprintf("http %d: %s", e.StatusCode, string(e.Body))
}
return fmt.Sprintf("http %d", e.StatusCode)
}