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';
|
2021-08-17 15:43:26 +00:00
|
|
|
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
|
2021-09-02 22:31:21 +00:00
|
|
|
import { sleepFor413RetryAfterTimeIfApplicable } from './sleepFor413RetryAfterTimeIfApplicable';
|
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-08-17 15:43:26 +00:00
|
|
|
if (!(err instanceof Error)) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
const code = parseIntWithFallback(err.code, -1);
|
|
|
|
if (code === 508) {
|
|
|
|
log.info('server responded with 508. Giving up on this job');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:31:21 +00:00
|
|
|
await sleepFor413RetryAfterTimeIfApplicable({ err, log, timeRemaining });
|
|
|
|
|
2021-08-17 15:43:26 +00:00
|
|
|
throw err;
|
|
|
|
}
|