Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent NodeApiError rewraping (no-changelog) #9627

8 changes: 7 additions & 1 deletion packages/workflow/src/errors/node-api.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface NodeOperationErrorOptions {
messageMapping?: { [key: string]: string }; // allows to pass custom mapping for error messages scoped to a node
functionality?: Functionality;
type?: string;
allowRewrapping?: boolean;
netroy marked this conversation as resolved.
Show resolved Hide resolved
}

interface NodeApiErrorOptions extends NodeOperationErrorOptions {
Expand Down Expand Up @@ -113,7 +114,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 @@ -129,8 +130,13 @@ export class NodeApiError extends NodeError {
level,
functionality,
messageMapping,
allowRewrapping: allowRewraping,
}: NodeApiErrorOptions = {},
) {
if (errorResponse instanceof NodeApiError && !allowRewraping) {
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 && !options.allowRewrapping) {
return error;
}
if (typeof error === 'string') {
error = new Error(error);
}

super(node, error);

if (error instanceof NodeError && error?.messages?.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow/test/errors/node.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('NodeError', () => {
it('should update re-wrapped error level and message', () => {
const apiError = new NodeApiError(node, { message: 'Some error happened', code: 500 });
const opsError = new NodeOperationError(node, mock(), { message: 'Some operation failed' });
const wrapped1 = new NodeOperationError(node, apiError);
const wrapped2 = new NodeOperationError(node, opsError);
const wrapped1 = new NodeOperationError(node, apiError, { allowRewrapping: true });
const wrapped2 = new NodeOperationError(node, opsError, { allowRewrapping: true });

expect(wrapped1.level).toEqual('error');
expect(wrapped1.message).toEqual('The service was not able to process your request');
Expand Down
Loading