From b6287f4839b9dba2dc25818f96d02d84ca3f983b Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Mon, 31 Jan 2022 11:58:20 -0800 Subject: [PATCH] Properly propagate 204 to fetchManifest --- ts/services/storage.ts | 9 +++++---- ts/services/storageRecordOps.ts | 7 ++++++- ts/textsecure/WebAPI.ts | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ts/services/storage.ts b/ts/services/storage.ts index c5c152315..a88348ac5 100644 --- a/ts/services/storage.ts +++ b/ts/services/storage.ts @@ -682,6 +682,11 @@ async function fetchManifest( return; } } catch (err) { + if (err.code === 204) { + log.info('storageService.fetchManifest: no newer manifest, ok'); + return; + } + log.error( 'storageService.fetchManifest: failed!', err && err.stack ? err.stack : String(err) @@ -691,10 +696,6 @@ async function fetchManifest( await createNewManifest(); return; } - if (err.code === 204) { - // noNewerManifest we're ok - return; - } throw err; } diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index 8b3042632..163b9cb68 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -423,7 +423,12 @@ function doRecordsConflict( // If both types are Long we can use Long's equals to compare them if (Long.isLong(localValue) || typeof localValue === 'number') { - if (!Long.isLong(remoteValue) || typeof remoteValue !== 'number') { + if (!Long.isLong(remoteValue) && typeof remoteValue !== 'number') { + log.info( + 'storageService.doRecordsConflict: Conflict found, remote value ' + + 'is not a number', + key + ); return true; } diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index b4a105721..bef2690b5 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -1381,17 +1381,29 @@ export function initialize({ ): Promise { const { credentials, greaterThanVersion } = options; - return _ajax({ + const { data, response } = await _ajax({ call: 'storageManifest', contentType: 'application/x-protobuf', host: storageUrl, httpType: 'GET', - responseType: 'bytes', + responseType: 'byteswithdetails', urlParameters: greaterThanVersion ? `/version/${greaterThanVersion}` : '', ...credentials, }); + + if (response.status === 204) { + throw makeHTTPError( + 'promiseAjax: error response', + response.status, + response.headers.raw(), + data, + new Error().stack + ); + } + + return data; } async function getStorageRecords(