Handle new rate limiting info from CDSI

This commit is contained in:
Fedor Indutny 2022-11-22 10:13:55 -08:00 committed by GitHub
parent b26f60d2fc
commit f0a3735ca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 36 deletions

View file

@ -0,0 +1,23 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export type RateLimitedErrorPayloadType = Readonly<{
// eslint-disable-next-line camelcase
retry_after?: number;
}>;
export class RateLimitedError extends Error {
public readonly retryAfterSecs: number;
// eslint-disable-next-line camelcase
constructor({ retry_after }: RateLimitedErrorPayloadType) {
super(
'RateLimitedError: got 4008 close code from CDSI, ' +
// eslint-disable-next-line camelcase
`retry_after=${retry_after}`
);
// eslint-disable-next-line camelcase
this.retryAfterSecs = retry_after ?? 0;
}
}