Add retry in indication to TooManyRequests http error
This commit is contained in:
parent
3397fd8216
commit
7db6c0e0c7
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wms-core",
|
||||
"version": "0.2.10",
|
||||
"version": "0.2.11",
|
||||
"description": "Node web framework",
|
||||
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
|
||||
"author": "Alice Gaudon <alice@gaudon.pro>",
|
||||
|
@ -59,10 +59,10 @@ export class NotFoundHttpError extends BadRequestError {
|
||||
}
|
||||
|
||||
export class TooManyRequestsHttpError extends BadRequestError {
|
||||
constructor(cause?: Error) {
|
||||
constructor(retryIn: number, cause?: Error) {
|
||||
super(
|
||||
`You're making too many requests!`,
|
||||
`We need some rest.`,
|
||||
`We need some rest. Please retry in ${Math.floor(retryIn / 1000)} seconds.`,
|
||||
'',
|
||||
cause
|
||||
);
|
||||
|
@ -54,7 +54,7 @@ class Throttle {
|
||||
let currentDate = new Date().getTime();
|
||||
|
||||
if (trigger.jailed && currentDate - trigger.jailed < this.jailPeriod) {
|
||||
this.throw();
|
||||
this.throw((trigger.jailed + this.jailPeriod) - currentDate);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -71,12 +71,12 @@ class Throttle {
|
||||
|
||||
if (trigger.count > this.max) {
|
||||
trigger.jailed = currentDate;
|
||||
this.throw();
|
||||
this.throw((trigger.jailed + this.jailPeriod) - currentDate);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private throw() {
|
||||
throw new TooManyRequestsHttpError();
|
||||
private throw(unjailedIn: number) {
|
||||
throw new TooManyRequestsHttpError(unjailedIn);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user