Closed creachadair closed 4 years ago
This seems to have some useful details: https://developer.twitter.com/en/support/twitter-api/error-troubleshooting
A couple of key points here:
"data"
and "errors"
returned together in the same response. The example given is looking up multiple tweets by ID, where some exist and others don't.From the OpenAPI schema:
curl https://api.twitter.com/2/openapi.json|jq '.components.schemas.Error'
{
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
This matches what's mentioned in the response codes doc. The schema also incorporates the RFC 7807 HTTP Problem Details object. That looks closer to what I'm getting.
Commit 3607a3d2 et seq. address part of this issue. The error wrapper now captures the error response and allows the caller to retrieve it, but I didn't add any data types for decoding the contents. The RFC 7807 schema looks more complicated than I really want to deal with right now.
Commit 30ee1684 addresses most of this, to the point where I'm going to consider this issue resolved. There are still some corner cases I think we don't handle, but the basic plumbing works and I can fix other errors as they arise.
On error, the v2 API reports a JSON text along with the status code. The exact format isn't clear, but it has the general shape:
The response codes are defined here: https://developer.twitter.com/en/docs/response-codes. In the wild, though, the format varies quite a bit. Sometimes the top-level message has status and details as additional keys:
Other times everything is inside the array:
The API docs don't appear to document the expected formats. Figure out some reasonable way to interpret these values, and attach them to error values.