Call `Error.captureStackTrace()` only when it is available.
Use `this.stack = (new Error).stack` when `captureStackTrace` is not
available but the `stack` property is (Firefox).
Modify ValidationError constructor to include the model name and
a human-readable representation of the validation errors (messages)
in the error message.
Before this change, the message was pointing the reader
to `err.details`. Most frameworks (e.g. express, mocha) log only
`err.message` but not other error properties, thus the logs were
rather unhelpful.
Example of the new error message:
The `User` instance is not valid. Details: `name` can't be blank.
Modify ValidationError constructor to include the model name and
a human-readable representation of the validation errors (messages)
in the error message.
Before this change, the message was pointing the reader
to `err.details`. Most frameworks (e.g. express, mocha) log only
`err.message` but not other error properties, thus the logs were
rather unhelpful.
Example of the new error message:
The `User` instance is not valid. Details: `name` can't be blank.
Modify the "unique" validator to accept additional property names to
narrow the space of rows searched for duplicates.
Example:
Consider `SiteUser` belongsTo `Site` via `siteId` foreign key.
Inside every site, the user email must be unique. It is allowed to
register the same email with multiple sites.
SiteUser.validateUniquenessOf('email', { scopedTo: ['siteId'] });
- change `statusCode` from 400 to 422
- nest `context` and `codes` inside `details`
- add `details.messages`
- reword the main error message
Remove the call to Error's constructor from ValidationError constructor,
because it's a no-op - Error's constructor creates a new
instance when called via `.call()`.