-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
exclusion-constraint-error.ts
33 lines (28 loc) · 1.03 KB
/
exclusion-constraint-error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useErrorCause } from '../../utils/deprecations.js';
import type { DatabaseErrorSubclassOptions } from '../database-error';
import { DatabaseError } from '../database-error';
interface ExclusionConstraintErrorOptions {
constraint?: string;
fields?: Record<string, string | number>;
table?: string;
}
/**
* Thrown when an exclusion constraint is violated in the database
*/
export class ExclusionConstraintError extends DatabaseError {
constraint: string | undefined;
fields: Record<string, string | number> | undefined;
table: string | undefined;
constructor(options: DatabaseErrorSubclassOptions & ExclusionConstraintErrorOptions = {}) {
if ('parent' in options) {
useErrorCause();
}
const parent = options.cause ?? options.parent ?? { sql: '', name: '', message: '' };
super(parent);
this.message = options.message || parent.message;
this.name = 'SequelizeExclusionConstraintError';
this.constraint = options.constraint;
this.fields = options.fields;
this.table = options.table;
}
}