Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
express-custom-response
Advanced tools
Create custom response methods for express.js
Install the module with: npm install express-custom-response
##Quick Start
require('express-custom-response')();
Module contain pre-defined custom responses:
res.serverError (extra)
return reponse with http code 500 and body:``` error: { error_message: 'We're sorry, a server error occurred. Please wait a bit and try again', error_code: 500, error_extra: null or extra }
**res.forbidden (fields, extra)**
- *object* **fields**
- Object which contain validation error, where key is field name and value is message
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 405 and body:```
error: {
error_message: 'Validation failed',
error_code: 405,
fields: {email: 'Email has to be uniq'},
error_extra: null or extra
}
res.notFound (name, extra)
return reponse with http code 404 and body:``` error: { error_message: 'User not found', error_code: 404, error_extra: null or extra }
**res.ok (extra)**
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 404 and body:```
{} or extra
If you want to add you own responses you should pass absolute path to module constructor
require('express-custom-response')(__dirname+ '/api/responses');
Then each script in this directory will be available as response method by filename. Example:
/**
* api/responses/accepted.js
*
* This will be available in controllers as res.accepted(message);
*/
module.exports = function(redirectTo, extra){
//this is points to express.response
this.status(202);
this.send(message);
}
If you want to override exists pre-defined response simple add new script to your directory with name of response which you want to override
FAQs
Create custom response methods for express.js
The npm package express-custom-response receives a total of 36 weekly downloads. As such, express-custom-response popularity was classified as not popular.
We found that express-custom-response demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.