aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.go
blob: a0f012ee830bea7da890e0e2698eb864f43868d2 (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
package http

import (
	"fmt"
	"net/http"
)

type HTTPError struct {
	Response *http.Response
}

func NewHTTPError(r *http.Response) *HTTPError {
	if r.StatusCode >= 200 && r.StatusCode < 300 {
		return nil
	}

	return &HTTPError{r}
}

func (e *HTTPError) StatusCode() int {
	return e.Response.StatusCode
}

func (e *HTTPError) Error() string {
	return fmt.Sprintf("Error requesting %q status code: %d",
		e.Response.Request.URL, e.Response.StatusCode,
	)
}