refactor(core): Reorganize error hierarchy in cli package (no-changelog) (#7839)

Ensure all errors in `cli` inherit from `ApplicationError` to continue
normalizing all the errors we report to Sentry

Follow-up to: https://github.com/n8n-io/n8n/pull/7820
This commit is contained in:
Iván Ovejero
2023-11-28 10:19:27 +01:00
committed by GitHub
parent 38f24a6184
commit 1c6178759c
81 changed files with 346 additions and 297 deletions

View File

@@ -1,15 +1,14 @@
import { Authorized, RestController, Get, Middleware } from '@/decorators';
import { WorkflowHistoryRequest } from '@/requests';
import { Service } from 'typedi';
import {
HistoryVersionNotFoundError,
SharedWorkflowNotFoundError,
WorkflowHistoryService,
} from './workflowHistory.service.ee';
import { WorkflowHistoryService } from './workflowHistory.service.ee';
import { Request, Response, NextFunction } from 'express';
import { isWorkflowHistoryEnabled, isWorkflowHistoryLicensed } from './workflowHistoryHelper.ee';
import { NotFoundError } from '@/ResponseHelper';
import { paginationListQueryMiddleware } from '@/middlewares/listQuery/pagination';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { SharedWorkflowNotFoundError } from '@/errors/shared-workflow-not-found.error';
import { WorkflowHistoryVersionNotFoundError } from '@/errors/workflow-history-version-not-found.error';
const DEFAULT_TAKE = 20;
@@ -67,7 +66,7 @@ export class WorkflowHistoryController {
} catch (e) {
if (e instanceof SharedWorkflowNotFoundError) {
throw new NotFoundError('Could not find workflow');
} else if (e instanceof HistoryVersionNotFoundError) {
} else if (e instanceof WorkflowHistoryVersionNotFoundError) {
throw new NotFoundError('Could not find version');
}
throw e;

View File

@@ -7,9 +7,8 @@ import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repo
import { Service } from 'typedi';
import { isWorkflowHistoryEnabled } from './workflowHistoryHelper.ee';
import { Logger } from '@/Logger';
export class SharedWorkflowNotFoundError extends Error {}
export class HistoryVersionNotFoundError extends Error {}
import { SharedWorkflowNotFoundError } from '@/errors/shared-workflow-not-found.error';
import { WorkflowHistoryVersionNotFoundError } from '@/errors/workflow-history-version-not-found.error';
@Service()
export class WorkflowHistoryService {
@@ -36,7 +35,7 @@ export class WorkflowHistoryService {
): Promise<Array<Omit<WorkflowHistory, 'nodes' | 'connections'>>> {
const sharedWorkflow = await this.getSharedWorkflow(user, workflowId);
if (!sharedWorkflow) {
throw new SharedWorkflowNotFoundError();
throw new SharedWorkflowNotFoundError('');
}
return this.workflowHistoryRepository.find({
where: {
@@ -52,7 +51,7 @@ export class WorkflowHistoryService {
async getVersion(user: User, workflowId: string, versionId: string): Promise<WorkflowHistory> {
const sharedWorkflow = await this.getSharedWorkflow(user, workflowId);
if (!sharedWorkflow) {
throw new SharedWorkflowNotFoundError();
throw new SharedWorkflowNotFoundError('');
}
const hist = await this.workflowHistoryRepository.findOne({
where: {
@@ -61,7 +60,7 @@ export class WorkflowHistoryService {
},
});
if (!hist) {
throw new HistoryVersionNotFoundError();
throw new WorkflowHistoryVersionNotFoundError('');
}
return hist;
}