handleRequestError converts a request error into an HTTPError or GraphQLError, first adding any endpoint scopes to the error's headers so that the scopes suggestion generated by handleResponse accounts for them. This is the error-path equivalent of calling EndpointNeedsScopes on a response before Ha
(err error, endpointScopes string)
| 304 | // accounts for them. This is the error-path equivalent of calling EndpointNeedsScopes on a response |
| 305 | // before HandleHTTPError, which call sites can no longer do when the response never reaches them. |
| 306 | func handleRequestError(err error, endpointScopes string) error { |
| 307 | if endpointScopes != "" { |
| 308 | if restErr, ok := errors.AsType[*ghAPI.HTTPError](err); ok && restErr.Headers != nil && restErr.StatusCode >= 400 && restErr.StatusCode < 500 { |
| 309 | oldScopes := restErr.Headers.Get("X-Accepted-Oauth-Scopes") |
| 310 | restErr.Headers.Set("X-Accepted-Oauth-Scopes", fmt.Sprintf("%s, %s", oldScopes, endpointScopes)) |
| 311 | } |
| 312 | } |
| 313 | return handleResponse(err) |
| 314 | } |
| 315 | |
| 316 | // handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an |
| 317 | // HTTPError or GraphQLError respectively. |
no test coverage detected