mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-28 08:39:03 +02:00
Fix panic for unauthorized response with nil error
This commit is contained in:
parent
cbab0bba29
commit
53c468062d
3
error.go
3
error.go
@ -38,6 +38,9 @@ func NewJiraError(resp *Response, httpError error) error {
|
||||
return errors.Wrap(err, httpError.Error())
|
||||
}
|
||||
} else {
|
||||
if httpError == nil {
|
||||
return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body))
|
||||
}
|
||||
return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body)))
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,25 @@ func TestError_NoJSON(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestError_Unauthorized_NilError(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
fmt.Fprint(w, `User is not authorized`)
|
||||
})
|
||||
|
||||
req, _ := testClient.NewRequest("GET", "/", nil)
|
||||
resp, _ := testClient.Do(req, nil)
|
||||
|
||||
err := NewJiraError(resp, nil)
|
||||
msg := err.Error()
|
||||
if !strings.Contains(msg, "401 Unauthorized:User is not authorized") {
|
||||
t.Errorf("Expected Unauthorized HTTP status: Got\n%s\n", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestError_BadJSON(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
Loading…
Reference in New Issue
Block a user