Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 417bfad

Browse files
authored
Handle HTTP status 409 and non-json errors better (#132)
2 parents 1b65852 + bd7704a commit 417bfad

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gitea/gitea.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
7070
return nil, errors.New("403 Forbidden")
7171
case 404:
7272
return nil, errors.New("404 Not Found")
73+
case 409:
74+
return nil, errors.New("409 Conflict")
7375
case 422:
7476
return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
7577
}
7678

7779
if resp.StatusCode/100 != 2 {
7880
errMap := make(map[string]interface{})
7981
if err = json.Unmarshal(data, &errMap); err != nil {
80-
return nil, err
82+
// when the JSON can't be parsed, data was probably empty or a plain string,
83+
// so we try to return a helpful error anyway
84+
return nil, fmt.Errorf("Unknown API Error: %d %s", resp.StatusCode, string(data))
8185
}
8286
return nil, errors.New(errMap["message"].(string))
8387
}

0 commit comments

Comments
 (0)