Better types for WebAPI
This commit is contained in:
parent
c05d23e628
commit
b9d6497cb1
22 changed files with 156 additions and 107 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
|
||||
import { HTTPError } from '../../textsecure/Errors';
|
||||
import { sleepFor413RetryAfterTimeIfApplicable } from './sleepFor413RetryAfterTimeIfApplicable';
|
||||
|
||||
export async function handleCommonJobRequestError({
|
||||
|
@ -14,7 +15,7 @@ export async function handleCommonJobRequestError({
|
|||
log: LoggerType;
|
||||
timeRemaining: number;
|
||||
}>): Promise<void> {
|
||||
if (!(err instanceof Error)) {
|
||||
if (!(err instanceof HTTPError)) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { LoggerType } from '../../types/Logging';
|
|||
import { sleep } from '../../util/sleep';
|
||||
import { parseRetryAfter } from '../../util/parseRetryAfter';
|
||||
import { isRecord } from '../../util/isRecord';
|
||||
import { HTTPError } from '../../textsecure/Errors';
|
||||
|
||||
export async function sleepFor413RetryAfterTimeIfApplicable({
|
||||
err,
|
||||
|
@ -17,7 +18,7 @@ export async function sleepFor413RetryAfterTimeIfApplicable({
|
|||
}>): Promise<void> {
|
||||
if (
|
||||
timeRemaining <= 0 ||
|
||||
!(err instanceof Error) ||
|
||||
!(err instanceof HTTPError) ||
|
||||
err.code !== 413 ||
|
||||
!isRecord(err.responseHeaders)
|
||||
) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import { getSendOptions } from '../util/getSendOptions';
|
|||
import { SignalService as Proto } from '../protobuf';
|
||||
import { handleMessageSend } from '../util/handleMessageSend';
|
||||
import type { CallbackResultType } from '../textsecure/Types.d';
|
||||
import { HTTPError } from '../textsecure/Errors';
|
||||
import { isSent } from '../messages/MessageSendState';
|
||||
import { getLastChallengeError, isOutgoing } from '../state/selectors/message';
|
||||
import { parseIntWithFallback } from '../util/parseIntWithFallback';
|
||||
|
@ -340,7 +341,7 @@ export class NormalMessageSendJobQueue extends JobQueue<NormalMessageSendJobData
|
|||
let maybe413Error: undefined | Error;
|
||||
messageSendErrors.forEach((messageSendError: unknown) => {
|
||||
formattedMessageSendErrors.push(Errors.toLogFormat(messageSendError));
|
||||
if (!(messageSendError instanceof Error)) {
|
||||
if (!(messageSendError instanceof HTTPError)) {
|
||||
return;
|
||||
}
|
||||
switch (parseIntWithFallback(messageSendError.code, -1)) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import { JobQueue } from './JobQueue';
|
|||
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
||||
import { parseIntWithFallback } from '../util/parseIntWithFallback';
|
||||
import type { WebAPIType } from '../textsecure/WebAPI';
|
||||
import { HTTPError } from '../textsecure/Errors';
|
||||
|
||||
const RETRY_WAIT_TIME = durations.MINUTE;
|
||||
const RETRYABLE_4XX_FAILURE_STATUSES = new Set([
|
||||
|
@ -83,7 +84,7 @@ export class ReportSpamJobQueue extends JobQueue<ReportSpamJobData> {
|
|||
map(serverGuids, serverGuid => server.reportMessage(e164, serverGuid))
|
||||
);
|
||||
} catch (err: unknown) {
|
||||
if (!(err instanceof Error)) {
|
||||
if (!(err instanceof HTTPError)) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue