Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return this.table.insert(data, params.rethinkdb).run().then(res => {
if (data[idField]) {
if (res.errors) {
return Promise.reject(new errors.Conflict('Duplicate primary key', res.errors));
}
return data;
} else { // add generated id
const addId = (current, index) => {
if (res.generated_keys && res.generated_keys[index]) {
return Object.assign({}, current, {
[idField]: res.generated_keys[index]
});
}
return current;
};
if (Array.isArray(data)) {
return data.map(addId);
}
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);
break;
case 500:
default:
error.errors = {
[key]: value
};
return Promise.reject(wrap(new errors.Conflict(error), error));
}
if (error.name) {
switch (error.name) {
case 'ValidationError':
case 'ValidatorError':
case 'CastError':
case 'VersionError':
return Promise.reject(wrap(new errors.BadRequest(error), error));
case 'OverwriteModelError':
return Promise.reject(wrap(new errors.Conflict(error), error));
case 'MissingSchemaError':
case 'DivergentArrayError':
return Promise.reject(wrap(new errors.GeneralError(error), error));
case 'MongoError':
return Promise.reject(wrap(new errors.GeneralError(error), error));
}
}
return Promise.reject(error);
};