Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
// 'options.schema' resolves to { permissions: '...', include: [ ... ] }
const items = getItems(context);
const options1 = Object.assign({}, optionsDefault, options);
const { schema, checkPermissions } = options1;
const schema1 = typeof schema === 'function' ? schema(context, options1) : schema;
const permissions = schema1.permissions || null;
const baseService = schema1.service;
const provider = ('provider' in schema1) ? schema1.provider : context.params.provider;
if (typeof checkPermissions !== 'function') {
throw new errors.BadRequest('Permissions param is not a function. (populate)');
}
if (baseService && context.path && baseService !== context.path) {
throw new errors.BadRequest(`Schema is for ${baseService} not ${context.path}. (populate)`);
}
if (permissions && !checkPermissions(context, context.path, permissions, 0)) {
throw new errors.BadRequest('Permissions do not allow this populate. (populate)');
}
if (typeof schema1 !== 'object') {
throw new errors.BadRequest('Schema does not resolve to an object. (populate)');
}
const include = []
.concat(schema1.include || [])
hook.data = hook.data || {};
const strategy = hook.data.strategy || strategies[0];
if (strategies.indexOf(strategy) === -1) {
return Promise.reject(new NotAuthenticated(`Strategy ${strategy} is not permitted`));
}
// Handle the case where authenticate hook was registered without a passport strategy specified
if (!strategy) {
return Promise.reject(new errors.GeneralError(`You must provide an authentication 'strategy'`));
}
// The client must send a `strategy` name.
if (!app.passport._strategy(strategy)) {
return Promise.reject(new errors.BadRequest(`Authentication strategy '${strategy}' is not registered.`));
}
// NOTE (EK): Passport expects an express/connect
// like request object. So we need to create one.
let request = {
query: hook.data,
body: hook.data,
params: hook.params,
headers: hook.params.headers || {},
cookies: hook.params.cookies || {},
session: {}
};
const strategyOptions = merge({}, app.passport.options(strategy), options);
debug(`Attempting to authenticate using ${strategy} strategy with options`, strategyOptions);
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') {
// NOTE (EK): Error codes taken from
// https://www.sqlite.org/c3ref/c_abort.html
switch (error.errno) {
case 1:
case 8:
case 18:
case 19:
case 20:
feathersError = new errors.BadRequest(message);
break;
case 2:
}).catch(err => {
console.log('err', err)
throw new errors.BadRequest('Error', {
errors: { message: err.toString() }
});
})
} else {
console.log('_state not found')
throw new errors.BadRequest('Error', {
errors: { message: 'BadRequest' }
});
}
}
} else {
console.log('ftablename not found')
throw new errors.BadRequest('Error', {
errors: { message: 'BadRequest' }
});
}
}
.then(() => {
throw new errors.BadRequest('Invalid token. Get for a new one. (authManagement)',
{ errors: { $className: 'badParam' } });
});
}
var deconstructId = token => {
if (token.indexOf('___') === -1) {
throw new errors.BadRequest('Token is not in the correct format.',
{ errors: { $className: 'badParams' } });
}
return token.slice(0, token.indexOf('___'));
};
this.id.forEach((idKey, index) => {
if (!ids) {
if (idList) {
if (idList[index]) {
query[idKey] = idList[index].length === 1 ? idList[index] : { $in: idList[index] };
}
} else {
query[idKey] = null;
}
} else if (ids[index]) {
query[idKey] = ids[index];
} else {
throw new errors.BadRequest('When using composite primary key, id must contain values for all primary keys');
}
});
} else {
(hook) => {
if (!hook.data.curve) {
throw new errors.BadRequest('Client must provide a curve with the request');
}
},
const { data } = hook;
if (!data) return hook;
const blacklist = data.blacklist;
if (!blacklist) return hook;
const userId = data.userId;
if(blacklist && blacklist.includes(userId)) {
throw new BadRequest('You can not blacklist yourself.');
}
const users = await hook.app.service('users').find({query: {_id: {$in: blacklist}}});
const unblacklistable = users.data.find((user) => {
return (user.role === 'admin') || (user.role === 'moderator');
});
if (unblacklistable){
throw new BadRequest('You can not blacklist admin users or moderators.');
}
return hook;
};
};
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;
}