|
| 1 | +export type SingleRowOperation = "findOne" | "updateOne" | "deleteOne"; |
| 2 | + |
| 3 | +export class OrmError extends Error { |
| 4 | + public override readonly name: string = "OrmError"; |
| 5 | + |
| 6 | + constructor(message: string) { |
| 7 | + super(message); |
| 8 | + Object.setPrototypeOf(this, OrmError.prototype); |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +export class NotFoundError extends OrmError { |
| 13 | + public override readonly name = "NotFoundError"; |
| 14 | + public readonly modelName: string; |
| 15 | + public readonly operation: SingleRowOperation; |
| 16 | + |
| 17 | + constructor( |
| 18 | + message: string, |
| 19 | + details: { modelName: string; operation: SingleRowOperation }, |
| 20 | + ) { |
| 21 | + super(message); |
| 22 | + this.modelName = details.modelName; |
| 23 | + this.operation = details.operation; |
| 24 | + Object.setPrototypeOf(this, NotFoundError.prototype); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +export class TooManyRowsError extends OrmError { |
| 29 | + public override readonly name = "TooManyRowsError"; |
| 30 | + public readonly modelName: string; |
| 31 | + public readonly operation: SingleRowOperation; |
| 32 | + public readonly rowCount: number; |
| 33 | + |
| 34 | + constructor( |
| 35 | + message: string, |
| 36 | + details: { |
| 37 | + modelName: string; |
| 38 | + operation: SingleRowOperation; |
| 39 | + rowCount: number; |
| 40 | + }, |
| 41 | + ) { |
| 42 | + super(message); |
| 43 | + this.modelName = details.modelName; |
| 44 | + this.operation = details.operation; |
| 45 | + this.rowCount = details.rowCount; |
| 46 | + Object.setPrototypeOf(this, TooManyRowsError.prototype); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +export class CreateFailedError extends OrmError { |
| 51 | + public override readonly name = "CreateFailedError"; |
| 52 | + public readonly modelName: string; |
| 53 | + |
| 54 | + constructor(message: string, details: { modelName: string }) { |
| 55 | + super(message); |
| 56 | + this.modelName = details.modelName; |
| 57 | + Object.setPrototypeOf(this, CreateFailedError.prototype); |
| 58 | + } |
| 59 | +} |
0 commit comments