cli / go-gh

A Go module for interacting with gh and the GitHub API from the command line.
https://pkg.go.dev/github.com/cli/go-gh/v2
MIT License
322 stars 45 forks source link

Export api.HTTPError #6

Closed sridharavinash closed 2 years ago

sridharavinash commented 2 years ago

This is an attempt to fix the issue mentioned in #4.

With the change in here, api.HTTPError would be exported and it would allow the caller to the REST API client to do things like

client, _ := gh.RESTClient(options)
err := client.Get(blah)
if err != nil {
    httpError := err.(*api.HTTPError)
    if httpError.StatusCode == 502 {
            ...retry
     }else{
            ...do something else
      }
}

Thanks for the 👀 💖 .

samcoe commented 2 years ago

@sridharavinash Thanks for opening this! I made one commit to move the HTTPError out of the internal directory, my understanding is that Go automatically keeps anything in that directory from being exported outside the package so we needed to move the code out of there also.