aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-23 00:34:40 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-23 00:34:40 +0200
commitb359f11ea09e642695edcd114b463da4395b10c1 (patch)
tree6f84c4693429a3815b7523e957801cdb420abb40 /clients/http/common.go
parent6f43e8933ba3c04072d5d104acc6118aac3e52ee (diff)
downloadgo-git-b359f11ea09e642695edcd114b463da4395b10c1.tar.gz
clients: supporting diferent protocols
Diffstat (limited to 'clients/http/common.go')
-rw-r--r--clients/http/common.go28
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,
+ )
+}