1.0.0 • Published 2 years ago
@smarterservices/sequelize-middleware v1.0.0
Sequelize Middleware
Introduction
This module is used to format the error and send user defined error in response.
Installation
Requirements
Install Process
- Clone project into your working directory.
- Open a
terminalin your projectroot directory. - Run
npm installto install necessary dependencies.
Configuration
- In your project directory, under
config/errorssubdirectory, list errors indefined-erros.jsonin following structure
{
"JOI": {
"ERROR_NAME": {
"code": "4000",
"message": "Joi related error message"
}
},
"ERROR_NAME": {
"code": "6000",
"message": "The error message to attach"
}
}All joi related errors will be listed under JOI object and other general errors will be listed as shown in the structure.
In your project directory, go to
configsubdirectory and modify the following things in configuration file (i.edefault.json).- Set
urlto attach additional url in Response Set
printErrorto true if you want to print error from moduleFor example, your configuration may look like as follows:
{ "errorResponse": { "url": "https://www.smarterservices.com/errors/", "printError": false } }
- Set
## Running Application/Code
* require module from anywhere
* use `formatError` to format the errorconst errorResponse = require('error-response');
const options = { values: { approvalSid: 'AP...', installSid: 'AI...' } }; const error = errorResponse.formatError('APPROVAL_NOT_FOUND_UNDER_INSTALL', options);
To generate the above error, the error object should be as follows
```JSON
{
"APPROVAL_NOT_FOUND_UNDER_INSTALL": {
"code": "6001",
"message": "approval '%approvalSid%' not found under '%installSid%'",
"status": 404
}
}- Here
approvalSidwill be replaced by the given inoptionsobject. - Default
statusCodeis 400, passing status in error object will override the defaultstatusCode. - It also expose
errorResponse.failActionto wrapjoirelated error.
Running Locally
n/a
Running in Production
n/a
External Dependencies
n/a
Deployment
- n/a
Cronjobs
- n/a