Skip to content

Commit 69ab7b9

Browse files
wxiaoguangHenry Goodman
authored and
Henry Goodman
committed
Caller should check the ResponseExtra.HasError() first to see whether the request fails (go-gitea#28796)
`resp != nil` doesn't mean the request really succeeded. Add a comment for requestJSONResp to clarify the behavior.
1 parent c763bb7 commit 69ab7b9

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

modules/private/actions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func GenerateActionsRunnerToken(ctx context.Context, scope string) (string, Resp
2222
})
2323

2424
resp, extra := requestJSONResp(req, &responseText{})
25-
if resp == nil {
25+
if extra.HasError() {
2626
return "", extra
2727
}
2828
return resp.Text, extra

modules/private/key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func AuthorizedPublicKeyByContent(ctx context.Context, content string) (string,
2727
req := newInternalRequest(ctx, reqURL, "POST")
2828
req.Param("content", content)
2929
resp, extra := requestJSONResp(req, &responseText{})
30-
if resp == nil {
30+
if extra.HasError() {
3131
return "", extra
3232
}
3333
return resp.Text, extra

modules/private/mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func SendEmail(ctx context.Context, subject, message string, to []string) (strin
3030
})
3131

3232
resp, extra := requestJSONResp(req, &responseText{})
33-
if resp == nil {
33+
if extra.HasError() {
3434
return "", extra
3535
}
3636
return resp.Text, extra

modules/private/request.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (re responseError) Error() string {
4747
// requestJSONResp sends a request to the gitea server and then parses the response.
4848
// If the status code is not 2xx, or any error occurs, the ResponseExtra.Error field is guaranteed to be non-nil,
4949
// and the ResponseExtra.UserMsg field will be set to a message for the end user.
50+
// Caller should check the ResponseExtra.HasError() first to see whether the request fails.
5051
//
5152
// * If the "res" is a struct pointer, the response will be parsed as JSON
5253
// * If the "res" is responseText pointer, the response will be stored as text in it

0 commit comments

Comments
 (0)