handle 421 on sending delete_all

pull/1969/head
Audric Ackermann 4 years ago
parent 32955c9ed5
commit f75f63e4e9
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

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

@ -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({ export const snodeHttpsAgent = new https.Agent({
rejectUnauthorized: false, rejectUnauthorized: false,
}); });
@ -561,7 +564,7 @@ async function handle421InvalidSwarm({
await Onions.incrementBadSnodeCountOrDrop({ snodeEd25519, associatedWith }); await Onions.incrementBadSnodeCountOrDrop({ snodeEd25519, associatedWith });
// this is important we throw so another retry is made and we exit the handling of that reponse // 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);
} }
/** /**

Loading…
Cancel
Save