Improve handling of 413 HTTP responses

This commit is contained in:
Evan Hahn 2021-09-27 09:44:09 -05:00 committed by GitHub
parent 8b98035cbf
commit 9791fa43ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 188 additions and 78 deletions

View file

@ -2,9 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
import type { LoggerType } from '../../types/Logging';
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
import { HTTPError } from '../../textsecure/Errors';
import { sleepFor413RetryAfterTimeIfApplicable } from './sleepFor413RetryAfterTimeIfApplicable';
import { sleepFor413RetryAfterTime } from './sleepFor413RetryAfterTime';
import { getHttpErrorCode } from './getHttpErrorCode';
export async function handleCommonJobRequestError({
err,
@ -15,17 +14,14 @@ export async function handleCommonJobRequestError({
log: LoggerType;
timeRemaining: number;
}>): Promise<void> {
if (!(err instanceof HTTPError)) {
throw err;
switch (getHttpErrorCode(err)) {
case 413:
await sleepFor413RetryAfterTime({ err, log, timeRemaining });
return;
case 508:
log.info('server responded with 508. Giving up on this job');
return;
default:
throw err;
}
const code = parseIntWithFallback(err.code, -1);
if (code === 508) {
log.info('server responded with 508. Giving up on this job');
return;
}
await sleepFor413RetryAfterTimeIfApplicable({ err, log, timeRemaining });
throw err;
}