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.)
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 gottype '_Map<String, dynamic>' is not a subtype of type 'List<dynamic>' (_TypeError)
atGitHub.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:
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.)