Page MenuHomePhabricator

D8997.id30476.diff
No OneTemporary

D8997.id30476.diff

diff --git a/lib/utils/services-utils.js b/lib/utils/services-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/utils/services-utils.js
@@ -0,0 +1,10 @@
+// @flow
+
+function handleHTTPResponseError(response: Response): void {
+ if (!response.ok) {
+ const { status, statusText } = response;
+ throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
+ }
+}
+
+export { handleHTTPResponseError };
diff --git a/native/backup/api.js b/native/backup/api.js
--- a/native/backup/api.js
+++ b/native/backup/api.js
@@ -6,6 +6,7 @@
import type { BackupAuth, BackupEncrypted } from 'lib/types/backup-types.js';
import { makeBackupServiceEndpointURL } from 'lib/utils/backup-service.js';
import { toBase64URL } from 'lib/utils/base64.js';
+import { handleHTTPResponseError } from 'lib/utils/services-utils.js';
import { getBackupBytesFromBlob } from './conversion-utils.js';
import { commUtilsModule } from '../native-modules.js';
@@ -50,10 +51,7 @@
},
);
- if (!sendBackupResponse.ok) {
- const { status, statusText } = sendBackupResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(sendBackupResponse);
}
async function getBackupID(username: string): Promise<string> {
@@ -65,10 +63,7 @@
},
);
- if (!getBackupIDResponse.ok) {
- const { status, statusText } = getBackupIDResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(getBackupIDResponse);
const blob = await getBackupIDResponse.blob();
const buffer = arrayBufferFromBlob(blob);
@@ -94,10 +89,7 @@
},
);
- if (!getUserKeysResponse.ok) {
- const { status, statusText } = getUserKeysResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(getUserKeysResponse);
const blob = await getUserKeysResponse.blob();
return getBackupBytesFromBlob(blob);
@@ -120,10 +112,7 @@
},
);
- if (!getUserDataResponse.ok) {
- const { status, statusText } = getUserDataResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(getUserDataResponse);
const blob = await getUserDataResponse.blob();
return getBackupBytesFromBlob(blob);
diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js
--- a/native/input/input-state-container.react.js
+++ b/native/input/input-state-container.react.js
@@ -102,6 +102,7 @@
generateReportID,
useIsReportEnabled,
} from 'lib/utils/report-utils.js';
+import { handleHTTPResponseError } from 'lib/utils/services-utils.js';
import {
type EditInputBarMessageParameters,
@@ -1186,10 +1187,7 @@
},
);
- if (!assignHolderResponse.ok) {
- const { status, statusText } = assignHolderResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(assignHolderResponse);
const { data_exists: dataExistsResponse } =
await assignHolderResponse.json();
blobAlreadyExists = dataExistsResponse;
diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js
--- a/web/input/input-state-container.react.js
+++ b/web/input/input-state-container.react.js
@@ -96,6 +96,7 @@
import { getConfig } from 'lib/utils/config.js';
import { getMessageForException, cloneError } from 'lib/utils/errors.js';
import { generateReportID } from 'lib/utils/report-utils.js';
+import { handleHTTPResponseError } from 'lib/utils/services-utils.js';
import {
type PendingMultimediaUpload,
@@ -1099,10 +1100,8 @@
},
);
- if (!assignHolderResponse.ok) {
- const { status, statusText } = assignHolderResponse;
- throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
- }
+ handleHTTPResponseError(assignHolderResponse);
+
const { data_exists: dataExistsResponse } =
await assignHolderResponse.json();
blobAlreadyExists = dataExistsResponse;

File Metadata

Mime Type
text/plain
Expires
Sat, Sep 28, 11:27 PM (17 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2198310
Default Alt Text
D8997.id30476.diff (4 KB)

Event Timeline