import { TSchemaValidationError } from './schema/parser.js' import { ProcedureCodes } from './procedure-codes.js' export class ProcedureError extends Error { constructor( readonly procedureName: string, readonly code: ProcedureCodes & number, readonly message: string, readonly meta?: object, ) { super(message) this.name = 'ProcedureError' // https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/ Object.setPrototypeOf(this, ProcedureError.prototype) } } export class ProcedureHookError extends ProcedureError { constructor( readonly procedureName: string, message: string, ) { super(procedureName, ProcedureCodes.PRECONDITION_FAILED, message) this.name = 'ProcedureHookError' // https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/ Object.setPrototypeOf(this, ProcedureHookError.prototype) } } export class ProcedureValidationError extends ProcedureError { constructor( readonly procedureName: string, message: string, readonly errors?: TSchemaValidationError[], ) { super(procedureName, ProcedureCodes.VALIDATION_ERROR, message) this.name = 'ProcedureValidationError' // https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/ Object.setPrototypeOf(this, ProcedureValidationError.prototype) } } export class ProcedureRegistrationError extends Error { constructor(readonly procedureName: string, message: string) { super(message) this.name = 'ProcedureRegistrationError' // https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/ Object.setPrototypeOf(this, ProcedureRegistrationError.prototype) } }