How to use the @feathersjs/errors.TooManyRequests 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 AZaviruha / feathers-hooks-ratelimit / index.js View on Github external
return async context => {
    let _namespace;

    if (namespace) {
      _namespace = namespace;
    } else {
      const user = context.params.user;
      _namespace = user ? user[userIdKey] : 'default';
    }

    try {
      await messageLimiter.consume(_namespace);
    } catch (e) {
      throw new errors.TooManyRequests(errorMessage || 'Too many requests', errorData);
    }

    return context;
  };
};