Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
feathersError = new errors.GeneralError(error);
}
if (error.data) {
feathersError.data = error.data;
}
throw feathersError;
}
// Postgres error code
// TODO
if (error.sqlState && error.sqlState.length) {
// remove SQLSTATE marker (#) and pad/truncate SQLSTATE to 5 chars
const sqlState = ('00000' + error.sqlState.replace('#', '')).slice(-5);
switch (sqlState.slice(0, 2)) {
case '02':
feathersError = new errors.NotFound(message);
break;
case '28':
feathersError = new errors.Forbidden(message);
break;
case '08':
case '0A':
case '0K':
feathersError = new errors.Unavailable(message);
break;
case '20':
case '21':
case '22':
case '23':
case '24':
case '25':
case '40':
case '42':
case '70':
feathersError = new errors.BadRequest(message);
break;
default:
feathersError = new errors.GeneralError(message);
}
} else if (error.code === 'SQLITE_ERROR') {
export default function errorHandler (error) {
error = error.nativeError || error;
let feathersError = error;
if (error.code === 'SQLITE_ERROR') {
switch (error.errno) {
case 1:
case 8:
case 18:
case 19:
case 20:
feathersError = new errors.BadRequest(error);
break;
case 2:
feathersError = new errors.Unavailable(error);
break;
case 3:
case 23:
feathersError = new errors.Forbidden(error);
break;
case 12:
feathersError = new errors.NotFound(error);
break;
default:
feathersError = new errors.GeneralError(error);
break;
}
throw feathersError;
}
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;
};
function toError (error) {
if (error.code === 'ECONNREFUSED') {
throw new Unavailable(error.message, _.pick(error, 'address', 'port', 'config'));
}
throw convert(error);
}