1
0
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:
Rekha Mittal 2019-03-19 11:27:47 -07:00 committed by Andy Grunwald
parent cbab0bba29
commit 53c468062d
2 changed files with 22 additions and 0 deletions

View File

@ -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)))
}

View File

@ -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()