From 99fb8a6e7f53a3d00a86a2d7b8424528dbd128eb Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 27 May 2020 14:20:54 +0200 Subject: [PATCH 1/3] if 500 error has ErrMsg return this else return request witch was made --- gitea/client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gitea/client.go b/gitea/client.go index 207266d..34a7190 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -110,6 +110,8 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re return nil, err } + errMap := make(map[string]interface{}) + switch resp.StatusCode { case 403: return nil, errors.New("403 Forbidden") @@ -120,11 +122,14 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re 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 err = json.Unmarshal(data, &errMap); err != nil { + return nil, fmt.Errorf("500 Internal Server Error, request: '%s' with '%s' method '%s' header and '%s' body", path, method, header, string(data)) + } + return nil, errors.New(errMap["message"].(string)) } if resp.StatusCode/100 != 2 { - errMap := make(map[string]interface{}) + 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 -- 2.40.1 From 95a881223b30bd7d37cd74e96f0801bdeb830874 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 8 Jul 2020 17:00:02 +0200 Subject: [PATCH 2/3] dedub --- gitea/client.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gitea/client.go b/gitea/client.go index 787ae05..ccbe10e 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -110,8 +110,6 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re return nil, err } - errMap := make(map[string]interface{}) - switch resp.StatusCode { case 403: return nil, errors.New("403 Forbidden") @@ -121,19 +119,14 @@ 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: - if err = json.Unmarshal(data, &errMap); err != nil { - return nil, fmt.Errorf("500 Internal Server Error, request: '%s' with '%s' method '%s' header and '%s' body", path, method, header, string(data)) - } - return nil, errors.New(errMap["message"].(string)) } if resp.StatusCode/100 != 2 { - + errMap := make(map[string]interface{}) 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)) } -- 2.40.1 From f6c2aa96903538f2a82fd5286cfbe4cd989253e0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 8 Jul 2020 19:04:16 +0200 Subject: [PATCH 3/3] ajust test for new gitea responce --- gitea/repo_commit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/repo_commit_test.go b/gitea/repo_commit_test.go index a339ad7..9132e15 100644 --- a/gitea/repo_commit_test.go +++ b/gitea/repo_commit_test.go @@ -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) } -- 2.40.1