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.
async-helper
Advanced tools
This package will read an array of async function responses and create a final, single response with error or success to Express.
This helper gets an array of async responses and create a final, single response to express.
Each function in async should set the err variable to true if an error occoured so async-helper will use it's response to create the HTML code and create the object that will be used by Express to send the response.
The default HTML code, if no error occoured is succes (200).
In your project root folder, run
$ npm install --save async-helper
You should call async-helper after the execution of your async functions, for instance:
var asyncHelper = require('async-helper');
/*
* START SERIAL FUNCTIONS
*/
async.series([
// Validate arguments
function(callback) {
args.validate(
mobletId, gitUrl, mobletName, mobletVersion,
gitCheckout, function(err, response) {
callback(err, response);
});
},
// GIT Clone
function(callback) {
git.clone(
mobletId, gitUrl, gitCheckout,
mobletVersion, function(err, response) {
callback(err, response);
});
},
/*
* START PARALLELL FUNCTIONS
*/
function(callback) {
async.parallel([
// Test Moblet with Jasmine
function(callback) {
moblet.runTests(mobletId, function(err, response) {
callback(err, response);
});
},
// Get Moblet definition
function(callback) {
moblet.getDefinitions(mobletId, function(err, response) {
callback(err, response);
});
}
],
// Parallel callback function
function(err, response) {
callback(err, response);
});
}
],
function(err, response) {
/***************************************************************************
* ASYNC-HELPER CALL
***************************************************************************/
var expressResponse = asyncHelper(err, response);
/**************************************************************************/
res.status(expressResponse.code)
.send(expressResponse);
});
};
Async-helper expects a boolean (err) and an array (response).
As this function is called after the execution of async, the boolean (err) should be set after all functions and be set to false if any of the functions had an error.
The array (response) is the array generated by the async execution.
In the functions executed by async, if some error occour, you should set a "code" in the response object sent to the callback.
Example:
module.exports = {
validate: function(gitCheckout, callback) {
var response = {};
var paramsMissing = [];
var err = false;
if (!gitCheckout) {
err = true;
paramsMissing.push('missing GIT checkout hash');
}
if (err === true) {
/*************************************************************************
* SET THE HTML ERROR CODE IN THE 'code' element
*************************************************************************/
response.code = 400;
/*************************************************************************
* SET OPTIONAL RESPONSES
*************************************************************************/
response.errors = paramsMissing;
}
callback(err, response);
}
};
After all the functions executions, you should get an array like this one:
[ // This array was generated in sequential functions
{
code: 400,
errors: ['missing GIT checkout hash']
},
{},
{},
[ // This array was generate in parallell as the last sequential function
{},
{
'en-US': {
mobletLabel: 'Fidelity Card',
mobletHint: 'Create a fidelity card to your customers'
},
'pt-BR': {
mobletLabel: 'Cartão de Fidelidade',
mobletHint: 'Crie um cartão de fidelidade para seus clientes'
},
{}
]
]
If some error occoured, you should get an object like this:
{
code: 405,
error: 'Moblet already exists. Perform PUT to update'
}
In a success, something like this:
Success example:
{
code: 200,
errors: [],
'en-US': {
mobletLabel: 'Fidelity Card',
mobletHint: 'Create a fidelity card to your customers'
},
'pt-BR': {
mobletLabel: 'Cartão de Fidelidade',
mobletHint: 'Crie um cartão de fidelidade para seus clientes'
}
}
FAQs
This package will read an array of async function responses and create a final, single response with error or success to Express.
The npm package async-helper receives a total of 9 weekly downloads. As such, async-helper popularity was classified as not popular.
We found that async-helper 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.