blob: 15338a832ce11063a34f687a5385a7ca0cae27ff (
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
|
package http
import (
"fmt"
"net/http"
"gopkg.in/src-d/go-git.v2/clients/common"
"gopkg.in/src-d/go-git.v2/core"
)
type HTTPError struct {
Response *http.Response
}
func NewHTTPError(r *http.Response) error {
if r.StatusCode >= 200 && r.StatusCode < 300 {
return nil
}
err := &HTTPError{r}
if r.StatusCode == 404 || r.StatusCode == 401 {
return core.NewPermanentError(common.NotFoundErr)
}
return core.NewUnexpectedError(err)
}
func (e *HTTPError) StatusCode() int {
return e.Response.StatusCode
}
func (e *HTTPError) Error() string {
return fmt.Sprintf("unexpected requesting %q status code: %d",
e.Response.Request.URL, e.Response.StatusCode,
)
}
|