Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const params = {}
if (store) params.store = store
// Add a worker to current step of the sequence
workers.push(runTask(task, params))
// When we reach the worker limit wait until the step finishes and jump to next one
if ((workers.length >= workersLimit) ||
(i === tasks.length - 1)) {
try {
const results = await Promise.all(workers)
const hrend = process.hrtime(hrstart)
const duration = (1000 * hrend[0] + hrend[1] / 1e6)
taskResults = taskResults.concat(results)
debug(results.length + ' tasks ran', results)
debug(taskResults.length + ` tasks ran from start in ${duration} ms`)
// Check if timeout has been reached
if (options.timeout && (duration > options.timeout)) throw new Timeout('Job timeout reached')
} catch (error) {
debug('Some tasks failed', error)
throw error
}
workers = []
}
i++
}
return taskResults
}
const timeoutId = setTimeout(() => reject(
new Timeout(`Timeout of ${this.timeout}ms exceeded calling ${method} on ${this.path}`, {
timeout: this.timeout,
method,
path: this.path
})
), this.timeout);
break;
case 404:
feathersError = new errors.NotFound(error);
break;
case 405:
feathersError = new errors.MethodNotAllowed(error);
break;
case 406:
feathersError = new errors.NotAcceptable(error);
break;
case 408:
feathersError = new errors.Timeout(error);
break;
case 409:
feathersError = new errors.Conflict(error);
break;
case 422:
feathersError = new errors.Unprocessable(error);
break;
case 501:
feathersError = new errors.NotImplemented(error);
break;
case 503:
feathersError = new errors.Unavailable(error);
exports.errorHandler = error => {
const { name, message } = error;
if (name.startsWith('Sequelize')) {
switch (name) {
case 'SequelizeValidationError':
case 'SequelizeUniqueConstraintError':
case 'SequelizeExclusionConstraintError':
case 'SequelizeForeignKeyConstraintError':
case 'SequelizeInvalidConnectionError':
throw wrap(new errors.BadRequest(message, { errors: error.errors }), error);
case 'SequelizeTimeoutError':
case 'SequelizeConnectionTimedOutError':
throw wrap(new errors.Timeout(message), error);
case 'SequelizeConnectionRefusedError':
case 'SequelizeAccessDeniedError':
throw wrap(new errors.Forbidden(message), error);
case 'SequelizeHostNotReachableError':
throw wrap(new errors.Unavailable(message), error);
case 'SequelizeHostNotFoundError':
throw wrap(new errors.NotFound(message), error);
default:
throw wrap(new errors.GeneralError(message), error);
}
}
throw error;
};