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