How to use the TooManyRequests function from http-errors

Find comprehensive JavaScript http-errors.TooManyRequests code examples handpicked from public code repositorys.

119
120
121
122
123
124
125
126
127
128
preconditionRequired: function preconditionRequired (message) {
  return new createError.PreconditionRequired(message)
},

tooManyRequests: function tooManyRequests (message) {
  return new createError.TooManyRequests(message)
},

requestHeaderFieldsTooLarge: function requestHeaderFieldsTooLarge (message) {
  return new createError.RequestHeaderFieldsTooLarge(message)
fork icon30
star icon340
watch icon17

+ 55 other calls in file

60
61
62
63
64
65
66
67
68

if (
  differenceInSeconds(new Date(), new Date(lastRequest)) <
  options.metrics[event]
) {
  throw new TooManyRequests()
}

await server.pg.write.query(metricsInsert({ event, os, version }))
fork icon21
star icon1
watch icon2

166
167
168
169
170
171
172
173
174
175
module.exports.Locked = new HTTPErrors.Locked()
module.exports.FailedDependency = new HTTPErrors.FailedDependency()
module.exports.UnorderedCollection = new HTTPErrors.UnorderedCollection()
module.exports.UpgradeRequired = new HTTPErrors.UpgradeRequired()
module.exports.PreconditionRequired = new HTTPErrors.PreconditionRequired()
module.exports.TooManyRequests = new HTTPErrors.TooManyRequests()
module.exports.RequestHeaderFieldsTooLarge = new HTTPErrors.RequestHeaderFieldsTooLarge()
module.exports.UnavailableForLegalReasons = new HTTPErrors.UnavailableForLegalReasons()
module.exports.InternalServerError = new HTTPErrors.InternalServerError()
module.exports.NotImplemented = new HTTPErrors.NotImplemented()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

-2
fork icon0
star icon3
watch icon2

+ 3 other calls in file

56
57
58
59
60
61
62
63
64
65
 */
const email = (req.body[conf.emailField] || '').toLowerCase();
if (!email) throw new HttpError.BadRequest('Missing Email');
if (!isEmail(email)) throw new HttpError.BadRequest('Invalid Email');
const tokens = await MagicTokens.find({ email, exp: { $gte: new Date() } }).toArray();
if (tokens.length >= conf.max) throw new HttpError.TooManyRequests('Token limit reached');

/**
 * Handle custom logic
 */
fork icon5
star icon25
watch icon3

149
150
151
152
153
154
155
156
157
158
case 426: {
  httpError = createError.UpgradeRequired();
  break;
}
case 429: {
  httpError = createError.TooManyRequests();
  break;
}
case 431: {
  httpError = createError.RequestHeaderFieldsTooLarge();
fork icon0
star icon0
watch icon2

+ 41 other calls in file