You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 13705e8
Browse filesBrowse the repository at this point in the historyBrowse files
fix(errors): match v2 problem types, explain X's errors, reject cut responses (#652)
EApiV2ErrorCode values are the problem types X returns again, and hasErrorCode compares them by their last part, on the whole error and on its errors array, so the api.twitter.com and api.x.com forms both match.
Error messages now include the title and detail of v2 errors without an errors array, without '(see about:blank)'. TwitterApi.getErrors returns [] for an error with an empty or non-JSON body.
A response cut before its end now rejects with ApiPartialResponseError whatever its parse mode, instead of resolving when the received part could be parsed as text or a buffer.
Copy file name to clipboardExpand all lines: doc/errors.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Some properties are common for both objects:
15
15
-`requestError`, an instance of `Error` that has been thrown through `request.on('error')` handler
16
16
17
17
## Specific properties of `ApiPartialResponseError`
18
-
-`responseError`, an instance of `Error` that has been thrown by `response.on('error')`, or by the tentative of parsing the result of a partial response
18
+
-`responseError`, an instance of `Error` that has been thrown by `response.on('error')` or by the tentative of parsing the response body, or that tells that the connection was closed before the end of the response
19
19
-`response`, containing raw node's `IncomingMessage` instance
20
20
-`rawContent`, containing all the chunks received from distant server
21
21
@@ -30,7 +30,7 @@ Some properties are common for both objects:
30
30
- (getter) `isAuthError`, `true` if this error is fired because logged user cannot do this action (invalid token, invalid app rights...)
31
31
32
32
## Specific methods of `ApiResponseError`
33
-
-`hasErrorCode(code: number | EApiV1ErrorCode | EApiV2ErrorCode)`: Tells if given Twitter error code is present in error response
33
+
-`hasErrorCode(code: number | EApiV1ErrorCode | EApiV2ErrorCode)`: Tells if given Twitter error code is present in error response. v2 problem types are compared by their last part (like `invalid-request`), so the `https://api.twitter.com/2/problems/…` and `https://api.x.com/2/problems/…` forms match each other
expect(error.message).to.equal('Request failed with code 403 - Forbidden: You are not permitted to perform this action.');
32
+
});
33
+
34
+
it('Should explain and match v2 problem types, whatever the host X gives them on',async()=>{
35
+
constforbidden=awaiterrorOf({
36
+
status: 403,
37
+
body: {title: 'Client Forbidden',detail: 'This request must be made using an approved developer account that is enrolled in the requested endpoint.',reason: 'client-not-enrolled',type: 'https://api.twitter.com/2/problems/client-forbidden'},
38
+
});
39
+
expect(forbidden.message).to.equal('Request failed with code 403 - Client Forbidden: This request must be made using an approved developer account that is enrolled in the requested endpoint. (see https://api.twitter.com/2/problems/client-forbidden)');
body: {errors: [{title: 'operational-disconnect',detail: 'This stream has been disconnected upstream for operational reasons.',type: 'https://api.x.com/2/problems/operational-disconnect'}]},
0 commit comments