handle 421 on sending delete_all

This commit is contained in:
Audric Ackermann 2021-10-04 10:57:52 +11:00
parent 32955c9ed5
commit f75f63e4e9
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
2 changed files with 14 additions and 2 deletions

View file

@ -1,8 +1,14 @@
import { default as insecureNodeFetch } from 'node-fetch';
import pRetry from 'p-retry';
import { Snode } from '../../data/data';
import { getStoragePubKey } from '../types';
import { lokiOnionFetch, snodeHttpsAgent, SnodeResponse } from './onions';
import {
ERROR_421_HANDLED_RETRY_REQUEST,
lokiOnionFetch,
snodeHttpsAgent,
SnodeResponse,
} from './onions';
interface FetchOptions {
method: string;
@ -81,6 +87,9 @@ async function lokiFetch({
if (e.code === 'ENOTFOUND') {
throw new window.textsecure.NotFoundError('Failed to resolve address', e);
}
if (e.message === ERROR_421_HANDLED_RETRY_REQUEST) {
throw new pRetry.AbortError(ERROR_421_HANDLED_RETRY_REQUEST);
}
throw e;
}
}

View file

@ -494,6 +494,9 @@ export async function processOnionResponse({
}
}
export const ERROR_421_HANDLED_RETRY_REQUEST =
'421 handled. Retry this request with a new targetNode';
export const snodeHttpsAgent = new https.Agent({
rejectUnauthorized: false,
});
@ -561,7 +564,7 @@ async function handle421InvalidSwarm({
await Onions.incrementBadSnodeCountOrDrop({ snodeEd25519, associatedWith });
// this is important we throw so another retry is made and we exit the handling of that reponse
throw new pRetry.AbortError(exceptionMessage);
throw new pRetry.AbortError(ERROR_421_HANDLED_RETRY_REQUEST);
}
/**