How to use the @feathersjs/errors.BadRequest function in @feathersjs/errors

To help you get started, we’ve selected a few @feathersjs/errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feathersjs-ecosystem / feathers-hooks-common / lib / services / populate.js View on Github external
.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 || [])
github feathersjs-ecosystem / authentication / lib / hooks / authenticate.js View on Github external
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);
github feathersjs-ecosystem / feathers-knex / lib / error-handler.js View on Github external
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:
github FlowzPlatform / workflow / service / src / services / dflowzdata / dflowzdata.hooks.js View on Github external
}).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' }
    });
  }

}
github feathers-plus / feathers-authentication-management / src / verifySignup.js View on Github external
.then(() => {
            throw new errors.BadRequest('Invalid token. Get for a new one. (authManagement)',
              { errors: { $className: 'badParam' } });
          });
      }
github feathers-plus / feathers-authentication-management / src / helpers.js View on Github external
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('___'));
};
github feathersjs-ecosystem / feathers-objection / src / index.js View on Github external
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 {
github jenkins-infra / evergreen / services / src / services / registration / registration.hooks.js View on Github external
(hook) => {
        if (!hook.data.curve) {
          throw new errors.BadRequest('Client must provide a curve with the request');
        }
      },
github Human-Connection / API / server / services / usersettings / hooks / validate-blacklist.js View on Github external
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;
  };
};
github feathersjs-ecosystem / feathers-objection / src / error-handler.js View on Github external
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;
    }