Skip to content

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

Description

@Hixie

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.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions