signal-desktop/ts/jobs/helpers/handleCommonJobRequestError.ts

29 lines
740 B
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { LoggerType } from '../../types/Logging';
import { sleepForRateLimitRetryAfterTime } from './sleepForRateLimitRetryAfterTime';
2021-09-27 14:44:09 +00:00
import { getHttpErrorCode } from './getHttpErrorCode';
export async function handleCommonJobRequestError({
err,
log,
timeRemaining,
}: Readonly<{
err: unknown;
log: LoggerType;
timeRemaining: number;
}>): Promise<void> {
2021-09-27 14:44:09 +00:00
switch (getHttpErrorCode(err)) {
case 413:
case 429:
await sleepForRateLimitRetryAfterTime({ err, log, timeRemaining });
2021-09-27 14:44:09 +00:00
return;
case 508:
log.info('server responded with 508. Giving up on this job');
return;
default:
throw err;
}
}