How to use the @feathersjs/errors.GeneralError 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 / feathers / packages / express / lib / error-handler.js View on Github external
return function (error, req, res, next) {
    // Set the error code for HTTP processing semantics
    error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500;

    // Log the error if it didn't come from a service method call
    if (options.logger && typeof options.logger.error === 'function' && !res.hook) {
      if (error.code >= 500) {
        options.logger.error(error);
      } else {
        options.logger.info(error);
      }
    }

    if (error.type !== 'FeathersError') {
      let oldError = error;
      error = new errors.GeneralError(oldError.message, {
        errors: oldError.errors
      });

      if (oldError.stack) {
        error.stack = oldError.stack;
      }
    }

    const formatter = {};

    // If the developer passed a custom function for ALL html errors
    if (typeof options.html === 'function') {
      formatter['text/html'] = options.html;
    } else {
      let file = options.html[error.code];
      if (!file) {
github feathersjs-ecosystem / feathers-mongodb / lib / error-handler.js View on Github external
module.exports = function errorHandler (error) {
  // NOTE (EK): The list of error code is way too massive to map
  // them to a specific error object so we'll use a generic one.
  // See https://github.com/mongodb/mongo/blob/master/docs/errors.md

  if (error.name === 'MongoError') {
    throw new errors.GeneralError(error, {
      ok: error.ok,
      code: error.code
    });
  }

  throw error;
};
github feathersjs-ecosystem / feathers-objection / src / error-handler.js View on Github external
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
  // Properly detect postgres error
  if (typeof error.code === 'string') {
    const pgerror = error.code.substring(0, 2);

    switch (pgerror) {
github feathersjs-ecosystem / feathers-objection / src / error-handler.js View on Github external
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;
  }

  // Objection validation error
  if (error.statusCode) {
    switch (error.statusCode) {
      case 400:
        feathersError = new errors.BadRequest(error);
        break;

      case 401:
        feathersError = new errors.NotAuthenticated(error);
        break;
github ijjk / mykb / src / services / docs / docs.class.js View on Github external
if (Array.isArray(data)) {
      return await Promise.all(data.map(current => this.create(current)))
    }
    const { name, dir, md } = data
    try {
      const rPath = path.join(dir, name)
      const docPath = path.join(this.docsDir, rPath)
      await fs.outputFile(docPath, md)

      if (this.useGit) {
        git.add(rPath).then(() => git.commit(`added doc ${rPath}`))
      }
      const ts = new Date().toJSON()
      return this.setDoc(path.join(dir, name), ts, md, ts)
    } catch (err) {
      throw new errors.GeneralError('could not create doc')
    }
  }
github feathersjs-ecosystem / feathers-objection / src / index.js View on Github external
constructor (options) {
    if (!options.model) {
      throw new errors.GeneralError('You must provide an Objection Model');
    }

    const whitelist = Object.values(OPERATORS).concat(options.whitelist || []);

    super(Object.assign({
      id: options.model.idColumn || 'id',
      whitelist
    }, options));

    this.idSeparator = options.idSeparator || ',';
    this.jsonSchema = options.model.jsonSchema;
    this.allowedEager = options.allowedEager && RelationExpression.create(options.allowedEager);
    this.namedEagerFilters = options.namedEagerFilters;
    this.eagerFilters = options.eagerFilters;
    this.allowedInsert = options.allowedInsert && RelationExpression.create(options.allowedInsert);
    this.insertGraphOptions = options.insertGraphOptions;
github feathersjs-ecosystem / feathers-hooks-common / lib / services / set-slug.js View on Github external
return context => {
    if (typeof field !== 'string') {
      field = `query.${slug}`;
    }

    if (context.type === 'after') {
      throw new errors.GeneralError('Cannot set slug on after hook. (setSlug)');
    }

    if (context.params && context.params.provider === 'rest') {
      const value = context.params.route[slug];
      if (typeof value === 'string' && value[0] !== ':') {
        setByDot(context.params, field, value);
      }
    }
  };
};
github feathersjs-ecosystem / feathers-elasticsearch / lib / index.js View on Github external
function errorHandler (error, id) {
  if (error instanceof errors.FeathersError) {
    throw error;
  }

  const statusCode = error.statusCode;

  if (statusCode === 404 && id !== undefined) {
    throw new errors.NotFound(`No record found for id '${id}'`);
  }

  if (errors[statusCode]) {
    throw new errors[statusCode](error.message, error);
  }

  throw new errors.GeneralError(error.message, error);
}
github Human-Connection / API / server / services / users / hooks / remove-all-related-user-data.js View on Github external
async function deleteData (service, query) {
      try {
        return await hook.app.service(service).remove(null, {query});
      } catch (err) {
        hook.app.error('ERROR ON SERVICE' + service);
        throw new errors.GeneralError(err.message);
      }
    }