Skip to content

Commit

Permalink
fix: error message format for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
parfeon committed Apr 16, 2024
1 parent 780fa90 commit a20ebf9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lib/errors/pubnub-api-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ export class PubNubAPIError extends Error {
errorData = errorResponse;
status = errorResponse.status;
}
if ('error' in errorResponse &&
typeof errorResponse.error === 'object' &&
!Array.isArray(errorResponse.error) &&
'message' in errorResponse.error) {
else
errorData = errorResponse;
if ('error' in errorResponse && errorResponse.error instanceof Error)
errorData = errorResponse.error;
}
}
}
catch (_) {
Expand Down
12 changes: 3 additions & 9 deletions src/errors/pubnub-api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,9 @@ export class PubNubAPIError extends Error {
) {
errorData = errorResponse;
status = errorResponse.status;
}
} else errorData = errorResponse;

if (
'error' in errorResponse &&
typeof errorResponse.error === 'object' &&
!Array.isArray(errorResponse.error!) &&
'message' in errorResponse.error!
) {
errorData = errorResponse.error;
}
if ('error' in errorResponse && errorResponse.error instanceof Error) errorData = errorResponse.error;
}
} catch (_) {
errorData = decoded;
Expand Down Expand Up @@ -164,6 +157,7 @@ export class PubNubAPIError extends Error {
public readonly errorData?: Error | Payload,
) {
super(message);

this.name = 'PubNubAPIError';
}

Expand Down

0 comments on commit a20ebf9

Please sign in to comment.