MCPcopy Create free account
hub / github.com/cli/cli / handleRequestError

Function handleRequestError

api/client.go:307–315  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

RequestWithContextMethod · 0.85

Calls 3

handleResponseFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected