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

Go SDK: Improve error handling and expose status #1185

Open
jessicasomaiya opened this issue Sep 28, 2022 · 0 comments
Open

Go SDK: Improve error handling and expose status #1185

jessicasomaiya opened this issue Sep 28, 2022 · 0 comments
Labels
enhancement New feature request go Go SDK issues p3 Priority 3

Comments

@jessicasomaiya
Copy link

Hello, I’ve been working with your Go SDK and I’ve enjoyed digging around to see how the generator works.

I’ve seen various discussions about decoding error responses as per the Swagger API spec, specifically #795 (comment) and I’d like to suggest one way of achieving this using the autogenerated models.

As the error models are defined in the v4 package, the rtl package cannot import the models as this would lead to a cyclic dependancy. This means the Do method https://github.com/looker-open-source/sdk-codegen/blob/main/go/rtl/auth.go#L89 must expose the error status and the body so the body can be decoded in the v4 package.

I have a PR of this implementation which I’d be interested to get your thoughts on. resolutionlife#5

As well as this, I need to access the specific status of the error response. This could be done through wrapping the error message in a well defined error type. For example see the below.

if err != nil {
        if errors.Is(err, v4.ErrNotFound) {
            …
        }
       return err
    }

where v4.ErrNotFound is defined like so

 var ErrNotFound = errors.New("not found")

This feature is also covered in my PR against a forked repo.

What are your thoughts on this approach to decoding the error responses?

@jeremytchang jeremytchang added p3 Priority 3 go Go SDK issues enhancement New feature request labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature request go Go SDK issues p3 Priority 3
Projects
None yet
Development

No branches or pull requests

2 participants