Improve handling of 413 HTTP responses
This commit is contained in:
parent
8b98035cbf
commit
9791fa43ef
7 changed files with 188 additions and 78 deletions
27
ts/jobs/helpers/getHttpErrorCode.ts
Normal file
27
ts/jobs/helpers/getHttpErrorCode.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { isRecord } from '../../util/isRecord';
|
||||
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
|
||||
|
||||
/**
|
||||
* Looks for an HTTP code. First tries the top level error, then looks at its `httpError`
|
||||
* property.
|
||||
*/
|
||||
export function getHttpErrorCode(maybeError: unknown): number {
|
||||
if (!isRecord(maybeError)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const maybeTopLevelCode = parseIntWithFallback(maybeError.code, -1);
|
||||
if (maybeTopLevelCode !== -1) {
|
||||
return maybeTopLevelCode;
|
||||
}
|
||||
|
||||
const { httpError } = maybeError;
|
||||
if (!isRecord(httpError)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return parseIntWithFallback(httpError.code, -1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue