Skip to content

Commit

Permalink
fix: Prevent NodeApiError rewraping (no-changelog) (#9627)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Jun 5, 2024
1 parent 411ffbd commit 37531cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/workflow/src/errors/node-api.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
* with an HTTP error code, an error message and a description.
*/
export class NodeApiError extends NodeError {
httpCode: string | null;
httpCode: string | null = null;

// eslint-disable-next-line complexity
constructor(
Expand All @@ -131,6 +131,10 @@ export class NodeApiError extends NodeError {
messageMapping,
}: NodeApiErrorOptions = {},
) {
if (errorResponse instanceof NodeApiError) {
return errorResponse;
}

super(node, errorResponse);

this.addToMessages(errorResponse.message as string);
Expand Down
4 changes: 4 additions & 0 deletions packages/workflow/src/errors/node-operation.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export class NodeOperationError extends NodeError {
error: Error | string | JsonObject,
options: NodeOperationErrorOptions = {},
) {
if (error instanceof NodeOperationError) {
return error;
}
if (typeof error === 'string') {
error = new Error(error);
}

super(node, error);

if (error instanceof NodeError && error?.messages?.length) {
Expand Down
8 changes: 2 additions & 6 deletions packages/workflow/test/errors/node.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ describe('NodeError', () => {
const wrapped1 = new NodeOperationError(node, apiError);
const wrapped2 = new NodeOperationError(node, opsError);

expect(wrapped1.level).toEqual('error');
expect(wrapped1.message).toEqual('The service was not able to process your request');
expect(wrapped1.tags).toEqual(expect.objectContaining({ reWrapped: true }));
expect(wrapped2.level).toEqual('error');
expect(wrapped2.message).toEqual('Some operation failed');
expect(wrapped2.tags).toEqual(expect.objectContaining({ reWrapped: true }));
expect(wrapped1).toEqual(apiError);
expect(wrapped2).toEqual(opsError);
});
});

0 comments on commit 37531cd

Please sign in to comment.