Impruve Error Handling (#351)
ajust test for new gitea responce dedub Merge branch 'master' into impruve-error-handling Merge branch 'master' into impruve-error-handling Merge branch 'master' into impruve-error-handling if 500 error has ErrMsg return this else return request witch was made Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/351 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: John Olheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
c388803b68
commit
27b4fdd986
2 changed files with 2 additions and 4 deletions
|
@ -119,8 +119,6 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
|
|||
return nil, errors.New("409 Conflict")
|
||||
case 422:
|
||||
return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
|
||||
case 500:
|
||||
return nil, fmt.Errorf("500 Internal Server Error, request: '%s' with '%s' method and '%s' header", path, method, header)
|
||||
}
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
|
@ -128,7 +126,7 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
|
|||
if err = json.Unmarshal(data, &errMap); err != nil {
|
||||
// when the JSON can't be parsed, data was probably empty or a plain string,
|
||||
// so we try to return a helpful error anyway
|
||||
return nil, fmt.Errorf("Unknown API Error: %d %s", resp.StatusCode, string(data))
|
||||
return nil, fmt.Errorf("Unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data))
|
||||
}
|
||||
return nil, errors.New(errMap["message"].(string))
|
||||
}
|
||||
|
|
|
@ -21,5 +21,5 @@ func TestListRepoCommits(t *testing.T) {
|
|||
l, err := c.ListRepoCommits(repo.Owner.UserName, repo.Name, ListCommitOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, l, 1)
|
||||
assert.EqualValues(t, "Initial commit", l[0].RepoCommit.Message)
|
||||
assert.EqualValues(t, "Initial commit\n", l[0].RepoCommit.Message)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue