Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status code extraction on response/error #4

Closed
sridharavinash opened this issue Dec 3, 2021 · 1 comment
Closed

Status code extraction on response/error #4

sridharavinash opened this issue Dec 3, 2021 · 1 comment

Comments

@sridharavinash
Copy link
Contributor

I had a quick question/feedback - I was wondering if a status code could be included along with the response from the gh.RESTClient().Get?

for example I was making a call

client, err := gh.RESTClient(options)
<snip>
err = client.Get("enterprises/avocado-corp/audit-log", &response)
Unfortunately err  cannot be type-casted to api.httperror since api.httperror is not exported, so Id have to rely on string parsing to figure out the error code here. Alternatively api.httpError could be exported to api.HTTPError , in which case the caller can then typecast the error and get all the relevant bits in the struct and do things like retry on certain statusCodes etc.
e.g
err = client.Get(blah)
if err != nil {
    httpError := err.(*api.HttpError)
    if httpError.statusCode == 502 {
            ...retry
     }else{
            ...do something else
      }
}

or the other option would be to read the statusCode, if it’s set on the response.

Does that make sense?

I started a PR to export api.HttpError here - 6596865

Thanks for reading ❤️ .

@samcoe
Copy link
Contributor

samcoe commented Dec 6, 2021

Closed in #6, this will be available in the next release.

@samcoe samcoe closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants