Skip to content

Commit d9eddf3

Browse files
author
Louis Béranger
committed
fix: Addresses #342
1 parent 1dc4f0d commit d9eddf3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/types/errors.types.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface TwitterErrorPayload<T = any> {
4040

4141
export interface TwitterApiErrorData {
4242
errors: (ErrorV1 | ErrorV2)[];
43+
error?: string;
4344
title?: string;
4445
detail?: string;
4546
type?: string;
@@ -184,7 +185,19 @@ export class ApiResponseError extends ApiError implements TwitterApiError, IBuil
184185
this.code = options.code;
185186
this.headers = options.headers;
186187
this.rateLimit = options.rateLimit;
187-
this.data = options.data;
188+
189+
// Fix bad error data payload on some v1 endpoints (see https://github.com/PLhery/node-twitter-api-v2/issues/342)
190+
if ('error' in options.data) {
191+
const data = { ...options.data };
192+
193+
data.errors = [{
194+
code: EApiV1ErrorCode.InternalError,
195+
message: data.error!,
196+
}];
197+
this.data = data;
198+
} else {
199+
this.data = options.data;
200+
}
188201
}
189202

190203
get request(): ClientRequest {

0 commit comments

Comments
 (0)