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

@@ -12,76 +12,7 @@ import type {
IWorkflowDb,
} from '@/Interfaces';
import { inDevelopment } from '@/constants';
/**
* Special Error which allows to return also an error code and http status code
*/
abstract class ResponseError extends Error {
/**
* Creates an instance of ResponseError.
* Must be used inside a block with `ResponseHelper.send()`.
*/
constructor(
message: string,
// The HTTP status code of response
readonly httpStatusCode: number,
// The error code in the response
readonly errorCode: number = httpStatusCode,
// The error hint the response
readonly hint: string | undefined = undefined,
) {
super(message);
this.name = 'ResponseError';
}
}
export class BadRequestError extends ResponseError {
constructor(message: string, errorCode?: number) {
super(message, 400, errorCode);
}
}
export class AuthError extends ResponseError {
constructor(message: string, errorCode?: number) {
super(message, 401, errorCode);
}
}
export class UnauthorizedError extends ResponseError {
constructor(message: string, hint: string | undefined = undefined) {
super(message, 403, 403, hint);
}
}
export class NotFoundError extends ResponseError {
constructor(message: string, hint: string | undefined = undefined) {
super(message, 404, 404, hint);
}
}
export class ConflictError extends ResponseError {
constructor(message: string, hint: string | undefined = undefined) {
super(message, 409, 409, hint);
}
}
export class UnprocessableRequestError extends ResponseError {
constructor(message: string, hint: string | undefined = undefined) {
super(message, 422, 422, hint);
}
}
export class InternalServerError extends ResponseError {
constructor(message: string, errorCode = 500) {
super(message, 500, errorCode);
}
}
export class ServiceUnavailableError extends ResponseError {
constructor(message: string, errorCode = 503) {
super(message, 503, errorCode);
}
}
import { ResponseError } from './errors/response-errors/abstract/response.error';
export function sendSuccessResponse(
res: Response,