How to use the @feathersjs/errors.MethodNotAllowed 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 / rest / getHandler.js View on Github external
return function (req, res, next) {
      const { query } = req;
      const route = omit(req.params, '__feathersId');

      res.setHeader('Allow', allowedMethods.join(','));

      // Check if the method exists on the service at all. Send 405 (Method not allowed) if not
      if (typeof service[method] !== 'function') {
        debug(`Method '${method}' not allowed on '${req.url}'`);
        res.status(statusCodes.methodNotAllowed);

        return next(new errors.MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`));
      }

      // Grab the service parameters. Use req.feathers
      // and set the query to req.query merged with req.params
      const params = Object.assign({
        query, route
      }, req.feathers);

      Object.defineProperty(params, '__returnHook', {
        value: true
      });

      const args = getArgs(req, params);

      debug(`REST handler calling \`${method}\` from \`${req.url}\``);
github feathersjs-ecosystem / feathers-hooks-common / lib / common / is-not.js View on Github external
module.exports = function (predicate) {
  if (typeof predicate !== 'function') {
    throw new errors.MethodNotAllowed('Expected function as param. (isNot)');
  }

  return context => {
    const result = predicate(context); // Should we pass a clone? (safety vs performance)

    if (!result || typeof result.then !== 'function') {
      return !result;
    }

    return result.then(result1 => !result1);
  };
};
github feathersjs / feathers / packages / transport-commons / src / socket / utils.ts View on Github external
const _run = () => {
    const lookup = app.lookup(path);

    // No valid service was found, return a 404
    // just like a REST route would
    if (lookup === null) {
      return Promise.reject(new errors.NotFound(`Service '${path}' not found`));
    }

    const { service, params: route = {} } = lookup;

    // Only service methods are allowed
    // @ts-ignore
    if (paramsPositions[method] === undefined || typeof service[method] !== 'function') {
      return Promise.reject(new errors.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`));
    }

    const position = paramsPositions[method];
    const query = methodArgs[position] || {};
    // `params` have to be re-mapped to the query
    // and added with the route
    const params = Object.assign({ query, route, connection }, connection);

    methodArgs[position] = params;

    // @ts-ignore
    return service[method](...methodArgs, true);
  };
github feathersjs / feathers / packages / adapter-commons / src / service.ts View on Github external
patch (id: NullableId, data: Partial, params?: Params): Promise {
    if (id === null && !this.allowsMulti('patch')) {
      return Promise.reject(new MethodNotAllowed(`Can not patch multiple entries`));
    }

    return callMethod(this, '_patch', id, data, params);
  }
github ijjk / mykb / src / services / docs / docs.class.js View on Github external
async update(id, data, params) {
    throw new errors.MethodNotAllowed('can not update on docs service')
  }
github feathersjs-ecosystem / feathers-objection / src / error-handler.js View on Github external
break;

      case 402:
        feathersError = new errors.PaymentError(error);
        break;

      case 403:
        feathersError = new errors.Forbidden(error);
        break;

      case 404:
        feathersError = new errors.NotFound(error);
        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);
github feathersjs / feathers / packages / adapter-commons / src / service.ts View on Github external
remove (id: NullableId, params?: Params): Promise {
    if (id === null && !this.allowsMulti('remove')) {
      return Promise.reject(new MethodNotAllowed(`Can not remove multiple entries`));
    }

    return callMethod(this, '_remove', id, params);
  }
}
github feathersjs-ecosystem / feathers-hooks-common / lib / services / is-provider.js View on Github external
module.exports = function (...providers) {
  if (!providers.length) {
    throw new errors.MethodNotAllowed('Calling iff() predicate incorrectly. (isProvider)');
  }

  return context => {
    const hookProvider = (context.params || {}).provider;

    return providers.some(provider => provider === hookProvider ||
      (provider === 'server' && !hookProvider) ||
      (provider === 'external' && hookProvider)
    );
  };
};
github feathersjs / feathers / packages / adapter-commons / src / service.ts View on Github external
create (data: Partial | Array>, params?: Params): Promise {
    if (Array.isArray(data) && !this.allowsMulti('create')) {
      return Promise.reject(new MethodNotAllowed(`Can not create multiple entries`));
    }

    return callMethod(this, '_create', data, params);
  }
github feathersjs-ecosystem / feathers-elasticsearch / lib / index.js View on Github external
raw (method, params = {}) {
    if (typeof method === 'undefined') {
      return Promise
        .reject(new errors.MethodNotAllowed('params.method must be defined.'))
        .catch(errorHandler);
    }

    return this.core.raw(this, method, params)
      .catch(errorHandler);
  }
}