aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-28 15:02:25 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-28 15:02:25 +0100
commit419ea1639230c5a7613962cbcbe0eb8b9e1ad078 (patch)
tree5d62c97c8d29d4bef9f4892783ca446f4ee7cdab /clients/http/common.go
parent7d6c5a56c0b63705378f125523876de1a97fd1ce (diff)
downloadgo-git-419ea1639230c5a7613962cbcbe0eb8b9e1ad078.tar.gz
clients: helpful error handling
Diffstat (limited to 'clients/http/common.go')
-rw-r--r--clients/http/common.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/clients/http/common.go b/clients/http/common.go
index a0f012e..2a2808c 100644
--- a/clients/http/common.go
+++ b/clients/http/common.go
@@ -3,18 +3,25 @@ package http
import (
"fmt"
"net/http"
+
+ "gopkg.in/src-d/go-git.v2/clients/common"
)
type HTTPError struct {
Response *http.Response
}
-func NewHTTPError(r *http.Response) *HTTPError {
+func NewHTTPError(r *http.Response) error {
if r.StatusCode >= 200 && r.StatusCode < 300 {
return nil
}
- return &HTTPError{r}
+ err := &HTTPError{r}
+ if r.StatusCode == 404 || r.StatusCode == 401 {
+ return common.NewPermanentError(common.NotFoundErr)
+ }
+
+ return common.NewUnexpectedError(err)
}
func (e *HTTPError) StatusCode() int {
@@ -22,7 +29,7 @@ func (e *HTTPError) StatusCode() int {
}
func (e *HTTPError) Error() string {
- return fmt.Sprintf("Error requesting %q status code: %d",
+ return fmt.Sprintf("unexpected requesting %q status code: %d",
e.Response.Request.URL, e.Response.StatusCode,
)
}