How to use the @feathersjs/errors.Unavailable 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-objection / src / error-handler.js View on Github external
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
github feathersjs-ecosystem / feathers-knex / lib / error-handler.js View on Github external
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') {
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;
    }

    throw feathersError;
  }
github feathersjs-ecosystem / feathers-sequelize / lib / utils.js View on Github external
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;
};
github feathersjs / feathers / packages / rest-client / lib / base.js View on Github external
function toError (error) {
  if (error.code === 'ECONNREFUSED') {
    throw new Unavailable(error.message, _.pick(error, 'address', 'port', 'config'));
  }

  throw convert(error);
}