diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 00:34:40 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 00:34:40 +0200 |
commit | b359f11ea09e642695edcd114b463da4395b10c1 (patch) | |
tree | 6f84c4693429a3815b7523e957801cdb420abb40 /clients/http/common.go | |
parent | 6f43e8933ba3c04072d5d104acc6118aac3e52ee (diff) | |
download | go-git-b359f11ea09e642695edcd114b463da4395b10c1.tar.gz |
clients: supporting diferent protocols
Diffstat (limited to 'clients/http/common.go')
-rw-r--r-- | clients/http/common.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clients/http/common.go b/clients/http/common.go new file mode 100644 index 0000000..a0f012e --- /dev/null +++ b/clients/http/common.go @@ -0,0 +1,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, + ) +} |