on failure error messages are discarded #582

Closed
opened 2022-04-26 15:41:54 +00:00 by dachary · 0 comments

During error handling the body of the response is read. If an error occurs (for instance 404) the data is returned (and passed to the caller) but eventually discarded.

As a result the error message is lost. An alternative would be for the caller to read it again from the body. However this is no longer possible because it is closed.

The only workaround is to manually craft the API call and repeat it with curl like so:

$ curl --verbose -H "content-type: application/json"  --data '{"title":"title","body":"body","head":"XVlBzgba:feature","base":"master"}' -H "Authorization: token REDACTED" "http://127.0.0.1:8781/api/v1/repos/root/XVlBzgba/pulls"
{"errors":null,"message":"GetUserByName","url":"http://0.0.0.0:8781/api/swagger"}
During [error handling](https://gitea.com/gitea/go-sdk/src/branch/master/gitea/client.go#L257-L293) the body of the response is read. If an error occurs (for [instance 404](https://gitea.com/gitea/go-sdk/src/branch/master/gitea/client.go#L257-L293)) the data is returned (and [passed to the caller](https://gitea.com/gitea/go-sdk/src/branch/master/gitea/client.go#L305)) but [eventually discarded](https://gitea.com/gitea/go-sdk/src/branch/master/gitea/client.go#L320). As a result the error message is lost. An alternative would be for the caller to read it again from the body. However this [is no longer possible](https://gitea.com/gitea/go-sdk/issues/551) because it is closed. The only workaround is to manually craft the API call and repeat it with curl like so: ``` $ curl --verbose -H "content-type: application/json" --data '{"title":"title","body":"body","head":"XVlBzgba:feature","base":"master"}' -H "Authorization: token REDACTED" "http://127.0.0.1:8781/api/v1/repos/root/XVlBzgba/pulls" {"errors":null,"message":"GetUserByName","url":"http://0.0.0.0:8781/api/swagger"} ```
6543 closed this issue 2022-04-28 02:56:33 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/go-sdk#582
No description provided.