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

Function handleRequestError

api/client.go:306–314  ·  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

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.
306func 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.

Callers 1

RequestWithContextMethod · 0.85

Calls 3

handleResponseFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected