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.29k stars 176 forks source link

[bug] TwitterApiErrorData.errors does not exist in some cases #357

Closed maximedupre closed 2 years ago

maximedupre commented 2 years ago

error.data is of type TwitterApiErrorData, which should have an attribute errors of type (ErrorV1 | Error V2)[].

However, in some cases it seems like it doesn't:

ApiResponseError: Request failed with code 401
    at RequestHandlerHelper.createResponseError (/app/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:103:16)
    at RequestHandlerHelper.onResponseEndHandler (/app/node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:252:25)
    at IncomingMessage.emit (node:events:525:35)
    at IncomingMessage.emit (node:domain:489:12)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  error: true,
  type: 'response',
  code: 401,
  headers: {
    'content-type': 'application/problem+json',
    'cache-control': 'no-cache, no-store, max-age=0',
    'content-length': '99',
    'x-response-time': '2',
    date: 'Tue, 30 Aug 2022 15:45:12 GMT',
    server: 'tsa_b',
    connection: 'close'
  },
  rateLimit: undefined,
  data: {
    title: 'Unauthorized',
    type: 'about:blank',
    status: 401,
    detail: 'Unauthorized'
  }
}

Should TwitterApiErrorData.errors be of type (ErrorV1 | Error V2)[] | undefined instead? Or is the error payload erroneous?

Thanks :)

alkihis commented 2 years ago

Hi, This can be a valid patch but this implies a breaking change. For now, consider accessing .errors getter on ApiResponseError that is already correctly typed :)