UNPKG

5.41 kBTypeScriptView Raw
1/**
2 * The Base Error all Sequelize Errors inherit from.
3 */
4export class BaseError extends Error {
5 public name: string;
6}
7
8/**
9 * Scope Error. Thrown when the sequelize cannot query the specified scope.
10 */
11export class SequelizeScopeError extends BaseError {}
12
13export class ValidationError extends BaseError {
14 /** Array of ValidationErrorItem objects describing the validation errors */
15 public readonly errors: ValidationErrorItem[];
16
17 /**
18 * Validation Error. Thrown when the sequelize validation has failed. The error contains an `errors`
19 * property, which is an array with 1 or more ValidationErrorItems, one for each validation that failed.
20 *
21 * @param message Error message
22 * @param errors Array of ValidationErrorItem objects describing the validation errors
23 */
24 constructor(message: string, errors?: ValidationErrorItem[]);
25
26 /**
27 * Gets all validation error items for the path / field specified.
28 *
29 * @param path The path to be checked for error items
30 */
31 public get(path: string): ValidationErrorItem[];
32}
33
34export class ValidationErrorItem {
35 /** An error message */
36 public readonly message: string;
37
38 /** The type of the validation error */
39 public readonly type: string;
40
41 /** The field that triggered the validation error */
42 public readonly path: string;
43
44 /** The value that generated the error */
45 public readonly value: string;
46
47 public readonly original: Error;
48
49 /**
50 * Validation Error Item
51 * Instances of this class are included in the `ValidationError.errors` property.
52 *
53 * @param message An error message
54 * @param type The type of the validation error
55 * @param path The field that triggered the validation error
56 * @param value The value that generated the error
57 */
58 constructor(message?: string, type?: string, path?: string, value?: string);
59}
60
61export interface CommonErrorProperties {
62 /** The database specific error which triggered this one */
63 readonly parent: Error;
64
65 /** The database specific error which triggered this one */
66 readonly original: Error;
67
68 /** The SQL that triggered the error */
69 readonly sql: string;
70}
71
72/**
73 * Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
74 */
75export class EmptyResultError extends BaseError {
76}
77
78export class DatabaseError extends BaseError implements CommonErrorProperties {
79 public readonly parent: Error;
80 public readonly original: Error;
81 public readonly sql: string;
82 public readonly parameters: Array<any>;
83 /**
84 * A base class for all database related errors.
85 * @param parent The database specific error which triggered this one
86 */
87 constructor(parent: Error);
88}
89
90/** Thrown when a database query times out because of a deadlock */
91export class TimeoutError extends DatabaseError {}
92
93export interface UniqueConstraintErrorOptions {
94 parent?: Error;
95 message?: string;
96 errors?: ValidationErrorItem[];
97 fields?: { [key: string]: unknown };
98 original?: Error;
99}
100
101/**
102 * Thrown when a unique constraint is violated in the database
103 */
104export class UniqueConstraintError extends ValidationError implements CommonErrorProperties {
105 public readonly parent: Error;
106 public readonly original: Error;
107 public readonly sql: string;
108 public readonly fields: { [key: string]: unknown };
109 constructor(options?: UniqueConstraintErrorOptions);
110}
111
112/**
113 * Thrown when a foreign key constraint is violated in the database
114 */
115export class ForeignKeyConstraintError extends DatabaseError {
116 public table: string;
117 public fields: { [field: string]: string };
118 public value: unknown;
119 public index: string;
120 constructor(options: { parent?: Error; message?: string; index?: string; fields?: string[]; table?: string });
121}
122
123/**
124 * Thrown when an exclusion constraint is violated in the database
125 */
126export class ExclusionConstraintError extends DatabaseError {
127 public constraint: string;
128 public fields: { [field: string]: string };
129 public table: string;
130 constructor(options: { parent?: Error; message?: string; constraint?: string; fields?: string[]; table?: string });
131}
132
133/**
134 * Thrown when attempting to update a stale model instance
135 */
136export class OptimisticLockError extends BaseError {
137 constructor(options: { message?: string, modelName?: string, values?: { [key: string]: any }, where?: { [key: string]: any } });
138}
139
140/**
141 * A base class for all connection related errors.
142 */
143export class ConnectionError extends BaseError {
144 public parent: Error;
145 public original: Error;
146 constructor(parent: Error);
147}
148
149/**
150 * Thrown when a connection to a database is refused
151 */
152export class ConnectionRefusedError extends ConnectionError {}
153
154/**
155 * Thrown when a connection to a database is refused due to insufficient privileges
156 */
157export class AccessDeniedError extends ConnectionError {}
158
159/**
160 * Thrown when a connection to a database has a hostname that was not found
161 */
162export class HostNotFoundError extends ConnectionError {}
163
164/**
165 * Thrown when a connection to a database has a hostname that was not reachable
166 */
167export class HostNotReachableError extends ConnectionError {}
168
169/**
170 * Thrown when a connection to a database has invalid values for any of the connection parameters
171 */
172export class InvalidConnectionError extends ConnectionError {}
173
174/**
175 * Thrown when a connection to a database times out
176 */
177export class ConnectionTimedOutError extends ConnectionError {}