Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): remaining transition lib/errors
- Loading branch information
Showing
27 changed files
with
359 additions
and
271 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import BaseError from './base-error'; | ||
|
||
/** | ||
* A wrapper for multiple Errors | ||
* | ||
* @param {Error[]} [errors] Array of errors | ||
* | ||
* @property errors {Error[]} | ||
*/ | ||
class AggregateError extends BaseError { | ||
errors: Array<AggregateError | Error>; | ||
|
||
constructor(errors: Array<AggregateError | Error>) { | ||
super(''); | ||
this.errors = errors; | ||
this.name = 'AggregateError'; | ||
} | ||
|
||
toString(): string { | ||
const message = `AggregateError of:\n${this.errors | ||
.map((error: Error | AggregateError) => | ||
error === this | ||
? '[Circular AggregateError]' | ||
: error instanceof AggregateError | ||
? String(error).replace(/\n$/, '').replace(/^/gm, ' ') | ||
: String(error).replace(/^/gm, ' ').substring(2) | ||
) | ||
.join('\n')}\n`; | ||
return message; | ||
} | ||
} | ||
|
||
export default AggregateError; |
8 changes: 3 additions & 5 deletions
8
lib/errors/association-error.js → lib/errors/association-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
'use strict'; | ||
|
||
const BaseError = require('./base-error'); | ||
import BaseError from './base-error'; | ||
|
||
/** | ||
* Thrown when an association is improperly constructed (see message for details) | ||
*/ | ||
class AssociationError extends BaseError { | ||
constructor(message) { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = 'SequelizeAssociationError'; | ||
} | ||
} | ||
|
||
module.exports = AssociationError; | ||
export default AssociationError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
import BaseError, { ErrorOptions } from './base-error'; | ||
|
||
interface IDatabaseError extends Error { | ||
/** | ||
* The SQL that triggered the error | ||
*/ | ||
sql?: string; | ||
|
||
/** | ||
* The parameters for the sql that triggered the error | ||
*/ | ||
parameters?: object; | ||
import BaseError, { CommonErrorProperties, ErrorOptions } from './base-error'; | ||
|
||
interface DatabaseErrorParent | ||
extends Error, | ||
Pick<CommonErrorProperties, 'sql'> { | ||
/** The parameters for the sql that triggered the error */ | ||
readonly parameters?: object; | ||
} | ||
|
||
interface DatabaseErrorSubclassOptions extends ErrorOptions { | ||
parent?: DatabaseErrorParent; | ||
message?: string; | ||
} | ||
|
||
/** | ||
* A base class for all database related errors. | ||
*/ | ||
class DatabaseError extends BaseError implements IDatabaseError { | ||
class DatabaseError | ||
extends BaseError | ||
implements DatabaseErrorParent, CommonErrorProperties | ||
{ | ||
parent: Error; | ||
original: Error; | ||
sql?: string; | ||
parameters?: object; | ||
sql: string; | ||
parameters: object; | ||
|
||
constructor(parent: IDatabaseError, options: ErrorOptions = {}) { | ||
constructor(parent: DatabaseErrorParent, options: ErrorOptions = {}) { | ||
super(parent.message); | ||
this.name = 'SequelizeDatabaseError'; | ||
|
||
this.parent = parent; | ||
this.original = parent; | ||
|
||
this.sql = parent.sql; | ||
this.parameters = parent.parameters; | ||
this.parameters = parent.parameters ?? {}; | ||
|
||
if (options.stack) { | ||
this.stack = options.stack; | ||
} | ||
} | ||
} | ||
|
||
module.exports = DatabaseError; | ||
export default DatabaseError; | ||
export { DatabaseErrorSubclassOptions, DatabaseErrorParent }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import DatabaseError, { DatabaseErrorSubclassOptions } from '../database-error'; | ||
|
||
interface ExclusionConstraintErrorOptions { | ||
constraint: string; | ||
fields: Record<string, string | number>; | ||
table: string; | ||
} | ||
|
||
/** | ||
* Thrown when an exclusion constraint is violated in the database | ||
*/ | ||
class ExclusionConstraintError | ||
extends DatabaseError | ||
implements ExclusionConstraintErrorOptions | ||
{ | ||
constraint: string; | ||
fields: Record<string, string | number>; | ||
table: string; | ||
|
||
constructor( | ||
options: DatabaseErrorSubclassOptions & ExclusionConstraintErrorOptions | ||
) { | ||
options = options || {}; | ||
options.parent = options.parent || { sql: '', name: '', message: '' }; | ||
|
||
super(options.parent, { stack: options.stack }); | ||
this.name = 'SequelizeExclusionConstraintError'; | ||
|
||
this.message = options.message || options.parent.message || ''; | ||
this.constraint = options.constraint; | ||
this.fields = options.fields; | ||
this.table = options.table; | ||
} | ||
} | ||
|
||
export default ExclusionConstraintError; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import DatabaseError, { DatabaseErrorSubclassOptions } from '../database-error'; | ||
|
||
enum RelationshipType { | ||
parent = 'parent', | ||
child = 'child', | ||
} | ||
|
||
interface ForeignKeyConstraintErrorOptions { | ||
table: string; | ||
fields: { [field: string]: string }; | ||
value: unknown; | ||
index: string; | ||
reltype: RelationshipType; | ||
} | ||
|
||
/** | ||
* Thrown when a foreign key constraint is violated in the database | ||
*/ | ||
class ForeignKeyConstraintError extends DatabaseError { | ||
table: string; | ||
fields: { [field: string]: string }; | ||
value: unknown; | ||
index: string; | ||
reltype: RelationshipType; | ||
|
||
constructor( | ||
options: ForeignKeyConstraintErrorOptions & DatabaseErrorSubclassOptions | ||
) { | ||
options = options || {}; | ||
options.parent = options.parent || { sql: '', name: '', message: '' }; | ||
|
||
super(options.parent, { stack: options.stack }); | ||
this.name = 'SequelizeForeignKeyConstraintError'; | ||
|
||
this.message = | ||
options.message || options.parent.message || 'Database Error'; | ||
this.fields = options.fields; | ||
this.table = options.table; | ||
this.value = options.value; | ||
this.index = options.index; | ||
this.reltype = options.reltype; | ||
} | ||
} | ||
|
||
export default ForeignKeyConstraintError; | ||
export { RelationshipType }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ErrorOptions } from '../base-error'; | ||
import DatabaseError, { DatabaseErrorParent } from '../database-error'; | ||
|
||
/** | ||
* Thrown when a database query times out because of a deadlock | ||
*/ | ||
class TimeoutError extends DatabaseError { | ||
constructor(parent: DatabaseErrorParent, options: ErrorOptions = {}) { | ||
super(parent, options); | ||
this.name = 'SequelizeTimeoutError'; | ||
} | ||
} | ||
|
||
export default TimeoutError; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.