aboutsummaryrefslogtreecommitdiffstats
path: root/err.go
blob: e05d1ff5393b2568784a8b21bca0546a3625e845 (plain) (blame)
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
package lulu

import (
	"fmt"
	"io"
	"net/http"
)

type errResp struct {
	*http.Response
}

func (e errResp) Error() string {
	resp := e.Response
	req := resp.Request
	body, _ := io.ReadAll(resp.Body)
	return fmt.Sprintf("lulu: %s %s: %s: %s", req.Method, req.URL, resp.Status, body)
}

type errReadResp struct {
	*http.Response
	error
}

func (e errReadResp) Error() string {
	req := e.Response.Request
	return fmt.Sprintf("lulu: %s %s: error reading response body: %v",
		req.Method, req.URL, e.error)
}

type errDecResp struct {
	*http.Response
	body []byte
	error
}

func (e errDecResp) Error() string {
	req := e.Response.Request
	return fmt.Sprintf("lulu: %s %s: error decoding response body %q: %v",
		req.Method, req.URL, string(e.body), e.error)
}