handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an HTTPError or GraphQLError respectively.
(err error)
| 162 | // handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an |
| 163 | // HTTPError or GraphQLError respectively. |
| 164 | func handleResponse(err error) error { |
| 165 | if err == nil { |
| 166 | return nil |
| 167 | } |
| 168 | |
| 169 | var restErr *ghAPI.HTTPError |
| 170 | if errors.As(err, &restErr) { |
| 171 | return HTTPError{ |
| 172 | HTTPError: restErr, |
| 173 | scopesSuggestion: generateScopesSuggestion(restErr.StatusCode, |
| 174 | restErr.Headers.Get("X-Accepted-Oauth-Scopes"), |
| 175 | restErr.Headers.Get("X-Oauth-Scopes"), |
| 176 | restErr.RequestURL.Hostname()), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | var gqlErr *ghAPI.GraphQLError |
| 181 | if errors.As(err, &gqlErr) { |
| 182 | return GraphQLError{ |
| 183 | GraphQLError: gqlErr, |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return err |
| 188 | } |
| 189 | |
| 190 | // ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth |
| 191 | // scopes in case a server response indicates that there are missing scopes. |
no test coverage detected