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

When GitHub reports an error, the API just throws a TypeError instead of throwing a useful exception #411

Open
Hixie opened this issue Nov 5, 2024 · 1 comment

Comments

@Hixie
Copy link
Contributor

Hixie commented Nov 5, 2024

For example, I tried calling addLabelsToIssue on an issue that, as it turns out, had been deleted. Instead of a useful exception telling me the response from GitHub, I got type '_Map<String, dynamic>' is not a subtype of type 'List<dynamic>' (_TypeError) at GitHub.requestJson (package:github/src/common/github.dart:335:35), which it turns out is not at all useful. (I had to add prints in the GitHub package to figure out what the problem was.)

For what it's worth, the response from GitHub looked like this:

{"message":"Validation Failed","errors":[{"resource":"Label","code":"unprocessable","field":"data","message":"Could not resolve to a node with the global id of 'I_kwDOAeUeuM6artTz'."}],"documentation_url":"https://docs.github.com/rest/issues/labels#add-labels-to-an-issue","status":"422"}

It seems like it's probably the case that we could add some general code to catch errors for all API calls and throw some general exceptions that encode the kinds of information GitHub returns. (Maybe HTTP status codes other than 200 should always throw, or something.)

Copy link

github-actions bot commented Nov 5, 2024

👋 Thanks for reporting! @robrbecker will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant