How to use the @feathersjs/errors.Conflict 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-rethinkdb / lib / index.js View on Github external
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);
        }
github feathersjs-ecosystem / feathers-objection / src / error-handler.js View on Github external
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:
github feathersjs-ecosystem / feathers-mongoose / lib / error-handler.js View on Github external
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);
};