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 | var restErr *ghAPI.HTTPError |
| 324 | if errors.As(err, &restErr) { |
| 325 | return HTTPError{ |
| 326 | HTTPError: restErr, |
| 327 | scopesSuggestion: generateScopesSuggestion(restErr.StatusCode, |
| 328 | restErr.Headers.Get("X-Accepted-Oauth-Scopes"), |
| 329 | restErr.Headers.Get("X-Oauth-Scopes"), |
| 330 | restErr.RequestURL.Hostname()), |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | var gqlErr *ghAPI.GraphQLError |
| 335 | if errors.As(err, &gqlErr) { |
| 336 | return GraphQLError{ |
| 337 | GraphQLError: gqlErr, |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return err |
| 342 | } |
| 343 | |
| 344 | // ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth |
| 345 | // scopes in case a server response indicates that there are missing scopes. |
no test coverage detected