PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.28k stars 176 forks source link

[bug] More bad error data payload on v1 endpoints? #354

Closed maximedupre closed 1 year ago

maximedupre commented 2 years ago

Describe the bug

TypeError: Cannot use 'in' operator to search for 'error' in <!DOCTYPE html>
<html lang="en" class="icecream">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=...
  File "/app/node_modules/twitter-api-v2/dist/types/errors.types.js", line 78, col 37, in new ApiResponseError
    if (options.data && 'error' in options.data && !options.data.errors) {
  File "/app/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js", line 103, col 16, in RequestHandlerHelper.createResponseError
    return new types_1.ApiResponseError(errorString, {
  File "/app/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js", line 252, col 25, in RequestHandlerHelper.onResponseEndHandler
    reject(this.createResponseError({ data, res: this.res, rateLimit, code }));
  File "node:events", line 513, col 28, in Gunzip.emit
  File "node:domain", line 489, col 12, in Gunzip.emit
  File "node:internal/streams/readable", line 1358, col 12, in endReadableNT
  File "node:internal/process/task_queues", line 83, col 21, in processTicksAndRejections
Xnapper-2022-08-26-14 12 21

To Reproduce

Not sure if this is because of a V1 endpoint though 🤔 The last request logged in Sentry was

https://api.twitter.com/2/tweets?ids=...

But it might be a previous request that failed, because it's all asynchronous.

But regardless the code should probably assume that options.data can be a string? 🤨

maximedupre commented 2 years ago

💡

https://twittercommunity.com/t/get-tweet-v2-returning-html-for-503-over-capacity/170961