mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Retain original error cause when throwing InternalServerError
This commit is contained in:
parent
fcbf0ea771
commit
c0a9063afd
|
@ -1,6 +1,5 @@
|
||||||
import type { AiAssistantSDK } from '@n8n_io/ai-assistant-sdk';
|
import type { AiAssistantSDK } from '@n8n_io/ai-assistant-sdk';
|
||||||
import type { Response } from 'express';
|
import type { Response } from 'express';
|
||||||
import { ErrorReporterProxy } from 'n8n-workflow';
|
|
||||||
import { strict as assert } from 'node:assert';
|
import { strict as assert } from 'node:assert';
|
||||||
import { WritableStream } from 'node:stream/web';
|
import { WritableStream } from 'node:stream/web';
|
||||||
|
|
||||||
|
@ -33,8 +32,7 @@ export class AiController {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e instanceof Error);
|
assert(e instanceof Error);
|
||||||
ErrorReporterProxy.error(e);
|
throw new InternalServerError(`Something went wrong: ${e.message}`, e);
|
||||||
throw new InternalServerError(`Something went wrong: ${e.message}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +44,7 @@ export class AiController {
|
||||||
return await this.aiService.applySuggestion(req.body, req.user);
|
return await this.aiService.applySuggestion(req.body, req.user);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e instanceof Error);
|
assert(e instanceof Error);
|
||||||
ErrorReporterProxy.error(e);
|
throw new InternalServerError(`Something went wrong: ${e.message}`, e);
|
||||||
throw new InternalServerError(`Something went wrong: ${e.message}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +54,7 @@ export class AiController {
|
||||||
return await this.aiService.askAi(req.body, req.user);
|
return await this.aiService.askAi(req.body, req.user);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e instanceof Error);
|
assert(e instanceof Error);
|
||||||
ErrorReporterProxy.error(e);
|
throw new InternalServerError(`Something went wrong: ${e.message}`, e);
|
||||||
throw new InternalServerError(`Something went wrong: ${e.message}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ export class CommunityPackagesController {
|
||||||
error instanceof Error ? error.message : UNKNOWN_FAILURE_REASON,
|
error instanceof Error ? error.message : UNKNOWN_FAILURE_REASON,
|
||||||
].join(':');
|
].join(':');
|
||||||
|
|
||||||
throw new InternalServerError(message);
|
throw new InternalServerError(message, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// broadcast to connected frontends that node list has been updated
|
// broadcast to connected frontends that node list has been updated
|
||||||
|
@ -283,7 +283,7 @@ export class CommunityPackagesController {
|
||||||
error instanceof Error ? error.message : UNKNOWN_FAILURE_REASON,
|
error instanceof Error ? error.message : UNKNOWN_FAILURE_REASON,
|
||||||
].join(':');
|
].join(':');
|
||||||
|
|
||||||
throw new InternalServerError(message);
|
throw new InternalServerError(message, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ export class PasswordResetController {
|
||||||
publicApi: false,
|
publicApi: false,
|
||||||
});
|
});
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
throw new InternalServerError(`Please contact your administrator: ${error.message}`);
|
throw new InternalServerError(`Please contact your administrator: ${error.message}`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class TranslationController {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||||
return require(NODE_HEADERS_PATH);
|
return require(NODE_HEADERS_PATH);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new InternalServerError('Failed to load headers file');
|
throw new InternalServerError('Failed to load headers file', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,9 @@ export abstract class ResponseError extends ApplicationError {
|
||||||
readonly errorCode: number = httpStatusCode,
|
readonly errorCode: number = httpStatusCode,
|
||||||
// The error hint the response
|
// The error hint the response
|
||||||
readonly hint: string | undefined = undefined,
|
readonly hint: string | undefined = undefined,
|
||||||
|
cause: unknown,
|
||||||
) {
|
) {
|
||||||
super(message);
|
super(message, { cause });
|
||||||
this.name = 'ResponseError';
|
this.name = 'ResponseError';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { ResponseError } from './abstract/response.error';
|
import { ResponseError } from './abstract/response.error';
|
||||||
|
|
||||||
export class InternalServerError extends ResponseError {
|
export class InternalServerError extends ResponseError {
|
||||||
constructor(message: string, errorCode = 500) {
|
constructor(message: string, cause?: unknown) {
|
||||||
super(message, 500, errorCode);
|
super(message, 500, 500, undefined, cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ export class ExecutionService {
|
||||||
requestFilters = requestFiltersRaw as IGetExecutionsQueryFilter;
|
requestFilters = requestFiltersRaw as IGetExecutionsQueryFilter;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new InternalServerError('Parameter "filter" contained invalid JSON string.');
|
throw new InternalServerError('Parameter "filter" contained invalid JSON string.', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { IUserSettings } from 'n8n-workflow';
|
import type { IUserSettings } from 'n8n-workflow';
|
||||||
import { ApplicationError, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
import { ApplicationError } from 'n8n-workflow';
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
|
|
||||||
import type { User, AssignableRole } from '@/databases/entities/user';
|
import type { User, AssignableRole } from '@/databases/entities/user';
|
||||||
|
@ -213,9 +213,8 @@ export class UserService {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorReporter.error(error);
|
|
||||||
this.logger.error('Failed to create user shells', { userShells: createdUsers });
|
this.logger.error('Failed to create user shells', { userShells: createdUsers });
|
||||||
throw new InternalServerError('An error occurred during user creation');
|
throw new InternalServerError('An error occurred during user creation', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingUsersToInvite.forEach(({ email, id }) => createdUsers.set(email, id));
|
pendingUsersToInvite.forEach(({ email, id }) => createdUsers.set(email, id));
|
||||||
|
|
|
@ -125,7 +125,7 @@ export class UserManagementMailer {
|
||||||
|
|
||||||
const error = toError(e);
|
const error = toError(e);
|
||||||
|
|
||||||
throw new InternalServerError(`Please contact your administrator: ${error.message}`);
|
throw new InternalServerError(`Please contact your administrator: ${error.message}`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ export class UserManagementMailer {
|
||||||
|
|
||||||
const error = toError(e);
|
const error = toError(e);
|
||||||
|
|
||||||
throw new InternalServerError(`Please contact your administrator: ${error.message}`);
|
throw new InternalServerError(`Please contact your administrator: ${error.message}`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -762,7 +762,7 @@ export async function executeWebhook(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const internalServerError = new InternalServerError(e.message);
|
const internalServerError = new InternalServerError(e.message, e);
|
||||||
if (e instanceof ExecutionCancelledError) internalServerError.level = 'warning';
|
if (e instanceof ExecutionCancelledError) internalServerError.level = 'warning';
|
||||||
throw internalServerError;
|
throw internalServerError;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue