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
**Note:** Top-level use of `await` is not available in most of Node.js usage. You might need to wrap `await`s into async functions. See [MDN related documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
109
-
110
-
### Basics
111
-
112
-
You want **to know more about client usage? See [the Basics](./doc/basics.md)**!
113
-
114
-
This lib also provide a bunch of helpers to work around Twitter API responses. See [the helpers part here](./doc/helpers.md).
71
+
## Documentation
72
+
73
+
Learn how to use the full potential of `twitter-api-v2`.
74
+
75
+
- Get started
76
+
-[Create a client and make your first request](./doc/basics.md)
Sometimes, you need to customize request settings (API prefix, body mode, response mode). You can pass request options through the **third parameter** of HTTP methods wrappers.
116
-
```ts
117
-
// [prefix]
118
-
// Customize API prefix (prefix that will be prepended to URL in first argument)
Paginators will automatically handle the rate limit when using `.fetchLast` or async iteration.
284
-
The `.fetchLast` or iteration will automatically ends when rate limit is hit.
285
-
286
-
Moreover, you can access current rate limit status for paginator's endpoint with the `.rateLimit` getter.
287
-
```ts
288
-
const paginator =awaitclient.v1.homeTimeline();
289
-
console.log(paginator.rateLimit); // { limit: number, remaining: number, reset: number }
290
-
```
291
-
292
-
## Error handling
293
-
294
-
When a request fails, you get a `ApiRequestError` or a `ApiResponseError` object (both instances of `Error`), that contain useful information about whats happening.
295
-
296
-
- An `ApiRequestError` happens when the request **failed to sent** (network error, bad URL...).
297
-
- An `ApiResponseError` happens when **Twitter replies with an error**.
298
-
299
-
Some properties are common for both objects:
300
-
-`error` is `true`
301
-
-`type` contains either `ETwitterApiError.Request` or `ETwitterApiError.Response` (depending of error)
302
-
-`request` containing node's raw `ClientRequest` instance
303
-
304
-
### Specific properties of `ApiRequestError`
305
-
-`requestError`, an instance of `Error` that has been thrown through `request.on('error')` handler
306
-
307
-
### Specific properties of `ApiResponseError`
308
-
-`data`, containing parsed Twitter response data (type of `TwitterApiErrorData`)
309
-
-`code` is a `number` containing the HTTP error code (`401`, `404`, ...)
310
-
-`response`, containing raw node's `IncomingMessage` instance
311
-
-`headers`, containing `IncomingHttpHeaders`
312
-
-`rateLimit` (can be undefined or `TwitterRateLimit`), containing parsed rate limit headers (if any)
313
-
- (getter) `errors`, direct access of parsed Twitter errors (`(ErrorV1 | ErrorV2)[]` or `undefined`)
314
-
- (getter) `rateLimitError`, `true` if this error is fired because a rate limit has been hit
315
-
- (getter) `isAuthError`, `true` if this error is fired because logged user cannot do this action (invalid token, invalid app rights...)
316
-
317
-
### Specific methods of `ApiResponseError`
318
-
-`hasErrorCode(code: number | EApiV1ErrorCode | EApiV2ErrorCode)`: Tells if given Twitter error code is present in error response
0 commit comments