2021-08-17 15:43:26 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-09-17 18:27:53 +00:00
|
|
|
import type { LoggerType } from '../../types/Logging';
|
2022-02-25 00:26:58 +00:00
|
|
|
import { sleepForRateLimitRetryAfterTime } from './sleepForRateLimitRetryAfterTime';
|
2021-09-27 14:44:09 +00:00
|
|
|
import { getHttpErrorCode } from './getHttpErrorCode';
|
2021-08-17 15:43:26 +00:00
|
|
|
|
2021-09-02 22:31:21 +00:00
|
|
|
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:
|
2022-02-25 00:26:58 +00:00
|
|
|
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;
|
2021-08-17 15:43:26 +00:00
|
|
|
}
|
|
|
|
}
|