mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
fix: Prevent NodeApiError rewraping (no-changelog) (#9627)
This commit is contained in:
parent
411ffbda7f
commit
37531cdb7d
|
@ -113,7 +113,7 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
|
||||||
* with an HTTP error code, an error message and a description.
|
* with an HTTP error code, an error message and a description.
|
||||||
*/
|
*/
|
||||||
export class NodeApiError extends NodeError {
|
export class NodeApiError extends NodeError {
|
||||||
httpCode: string | null;
|
httpCode: string | null = null;
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
// eslint-disable-next-line complexity
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -131,6 +131,10 @@ export class NodeApiError extends NodeError {
|
||||||
messageMapping,
|
messageMapping,
|
||||||
}: NodeApiErrorOptions = {},
|
}: NodeApiErrorOptions = {},
|
||||||
) {
|
) {
|
||||||
|
if (errorResponse instanceof NodeApiError) {
|
||||||
|
return errorResponse;
|
||||||
|
}
|
||||||
|
|
||||||
super(node, errorResponse);
|
super(node, errorResponse);
|
||||||
|
|
||||||
this.addToMessages(errorResponse.message as string);
|
this.addToMessages(errorResponse.message as string);
|
||||||
|
|
|
@ -13,9 +13,13 @@ export class NodeOperationError extends NodeError {
|
||||||
error: Error | string | JsonObject,
|
error: Error | string | JsonObject,
|
||||||
options: NodeOperationErrorOptions = {},
|
options: NodeOperationErrorOptions = {},
|
||||||
) {
|
) {
|
||||||
|
if (error instanceof NodeOperationError) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
if (typeof error === 'string') {
|
if (typeof error === 'string') {
|
||||||
error = new Error(error);
|
error = new Error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
super(node, error);
|
super(node, error);
|
||||||
|
|
||||||
if (error instanceof NodeError && error?.messages?.length) {
|
if (error instanceof NodeError && error?.messages?.length) {
|
||||||
|
|
|
@ -12,11 +12,7 @@ describe('NodeError', () => {
|
||||||
const wrapped1 = new NodeOperationError(node, apiError);
|
const wrapped1 = new NodeOperationError(node, apiError);
|
||||||
const wrapped2 = new NodeOperationError(node, opsError);
|
const wrapped2 = new NodeOperationError(node, opsError);
|
||||||
|
|
||||||
expect(wrapped1.level).toEqual('error');
|
expect(wrapped1).toEqual(apiError);
|
||||||
expect(wrapped1.message).toEqual('The service was not able to process your request');
|
expect(wrapped2).toEqual(opsError);
|
||||||
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 }));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue