16 lines
462 B
TypeScript
16 lines
462 B
TypeScript
// Copyright 2021 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { isNormalNumber } from './isNormalNumber';
|
|
|
|
const ONE_SECOND = 1000;
|
|
const MINIMAL_RETRY_AFTER = ONE_SECOND;
|
|
|
|
export function parseRetryAfter(value: string): number {
|
|
let retryAfter = parseInt(value, 10);
|
|
if (!isNormalNumber(retryAfter) || retryAfter.toString() !== value) {
|
|
retryAfter = 0;
|
|
}
|
|
|
|
return Math.max(retryAfter * ONE_SECOND, MINIMAL_RETRY_AFTER);
|
|
}
|