handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an HTTPError or GraphQLError respectively.
(err error)
| 316 | // handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an |
| 317 | // HTTPError or GraphQLError respectively. |
| 318 | func handleResponse(err error) error { |
| 319 | if err == nil { |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | if restErr, ok := errors.AsType[*ghAPI.HTTPError](err); ok { |
| 324 | return HTTPError{ |
| 325 | HTTPError: restErr, |
| 326 | scopesSuggestion: generateScopesSuggestion(restErr.StatusCode, |
| 327 | restErr.Headers.Get("X-Accepted-Oauth-Scopes"), |
| 328 | restErr.Headers.Get("X-Oauth-Scopes"), |
| 329 | restErr.RequestURL.Hostname()), |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if gqlErr, ok := errors.AsType[*ghAPI.GraphQLError](err); ok { |
| 334 | return GraphQLError{ |
| 335 | GraphQLError: gqlErr, |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | return err |
| 340 | } |
| 341 | |
| 342 | // ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth |
| 343 | // scopes in case a server response indicates that there are missing scopes. |
no test coverage detected