Errors
Error objects are exposed via the base SequelizeMock object and can be used in much the same
way that native Sequelize errors can be used. Because no queries are run, any errors that
would normally contain a sql
property include it with a value indicating this is test code
NOTE: Error names are copied exactly from Sequelize in the off-chance code is relying on error name instead of equality or instanceof
new BaseError()
BaseError is the base class most other Sequelize Mock Error classes inherit from
Mostly based off of the Sequelize.js equivalent code
Extends Error
Alias Error
new ValidationError(msg, [errors])
ValidationError is the class used for validation errors returned by Sequelize Mock.
The most common way you will see this error is using the $addValidationError
test
helper method on instances.
ValidationErrors contain an errors
property which contains a list of the specific
validation errors that were encountered. For example, if two validation errors were
encountered, it will be an array of length two. Objects in this array are of type
ValidationErrorItem
.
Extends BaseError
See
Parameters
Name | Type | Description |
---|---|---|
msg | String | Error Message |
[errors] | Array.<ValidationErrorItem> | Error Message |
.errors
Array of all validation errors that were encountered with this validation
#get(path) -> Array.<ValidationErrorItem>
Get the validation error for a particular field
Parameters
Name | Type | Description |
---|---|---|
path | String | Field you would like the list of validation errors for |
Return
Array.<ValidationErrorItem>
: Array of validation errors for the given field
new ValidationErrorItem(msg, type, path, value)
A specific validation failure result
See
- ValidationError
Parameters
Name | Type | Description |
---|---|---|
msg | String | Error Message |
type | String | Type of the error |
path | String | Field with the error |
value | String | Value with the error |
new DatabaseError(parentError)
The generic base Database Error class
Extends BaseError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
.sql
Ordinarily contains the SQL that triggered the error. However, because test code does not go to the DB and therefore does not have SQL, this will contain an SQL comment stating it is from Sequelize Mock.
new TimeoutError()
Database timeout error
Extends DatabaseError
new UniqueConstraintError(opts)
Unique constraint violation error
Extends ValidationError, DatabaseError
Parameters
Name | Type | Description |
---|---|---|
opts | Object | Unique constraint error information |
opts.message | String | Error message |
[opts.errors] | Array.<ValidationErrorItem> | Errors that were encountered |
[opts.fields] | Array.<String> | Fields that violated the unique constraint |
new ForeignKeyConstraintError(opts)
Foreign key constraint violation error
Extends BaseError, DatabaseError
Parameters
Name | Type | Description |
---|---|---|
opts | Object | Unique constraint error information |
opts.message | String | Error message |
[opts.fields] | Array.<String> | Fields that violated the unique constraint |
opts.table | String | Name of the table the failure is for |
opts.value | String | Invalid value |
opts.index | String | Name of the foreign key index that was violated |
new ExclusionConstraintError(opts)
Exclusion constraint violation error
Extends BaseError, DatabaseError
Parameters
Name | Type | Description |
---|---|---|
opts | Object | Unique constraint error information |
opts.message | String | Error message |
[opts.fields] | Array.<String> | Fields that violated the unique constraint |
opts.table | String | Name of the table the failure is for |
opts.constraint | String | Name of the constraint that was violated |
new ConnectionError(parentError)
Generic database connection error
Extends BaseError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new ConnectionRefusedError(parentError)
Database connection refused error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new AccessDeniedError(parentError)
Database access denied connection error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new HostNotFoundError(parentError)
Database host not found connection error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new HostNotReachableError(parentError)
Database host not reachable connection error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new InvalidConnectionError(parentError)
Database invalid connection error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new ConnectionTimedOutError(parentError)
Database connection timed out error
Extends ConnectionError
Parameters
Name | Type | Description |
---|---|---|
parentError | Error | Original error that triggered this error |
new InstanceError(message)
Error from a Sequelize (Mock) Instance
Extends BaseError
Parameters
Name | Type | Description |
---|---|---|
message | Error | Error message |