Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3168679
D10131.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10131.diff
View Options
diff --git a/keyserver/src/services/blob.js b/keyserver/src/services/blob.js
--- a/keyserver/src/services/blob.js
+++ b/keyserver/src/services/blob.js
@@ -5,7 +5,6 @@
getBlobFetchableURL,
makeBlobServiceEndpointURL,
} from 'lib/utils/blob-service.js';
-import { getMessageForException } from 'lib/utils/errors.js';
import { createHTTPAuthorizationHeader } from 'lib/utils/services-utils.js';
import { verifyUserLoggedIn } from '../user/login.js';
@@ -36,7 +35,21 @@
+holder: string,
};
-async function uploadBlob(blob: Blob, hash: string): Promise<void> {
+type BlobOperationResult =
+ | {
+ +success: true,
+ }
+ | {
+ +success: false,
+ +reason: 'HASH_IN_USE' | 'OTHER',
+ +status: number,
+ +statusText: string,
+ };
+
+async function uploadBlob(
+ blob: Blob,
+ hash: string,
+): Promise<BlobOperationResult> {
const formData = new FormData();
formData.append('blob_hash', hash);
formData.append('blob_data', blob);
@@ -53,11 +66,21 @@
if (!uploadBlobResponse.ok) {
const { status, statusText } = uploadBlobResponse;
- throw new Error(`Payload upload failed with HTTP ${status}: ${statusText}`);
+ const reason = status === 409 ? 'HASH_IN_USE' : 'OTHER';
+ return {
+ success: false,
+ reason,
+ status,
+ statusText,
+ };
}
+
+ return { success: true };
}
-async function assignHolder(params: BlobDescriptor): Promise<void> {
+async function assignHolder(
+ params: BlobDescriptor,
+): Promise<BlobOperationResult> {
const { hash, holder } = params;
const headers = await createRequestHeaders();
const assignHolderResponse = await fetch(
@@ -74,23 +97,39 @@
if (!assignHolderResponse.ok) {
const { status, statusText } = assignHolderResponse;
- throw new Error(
- `Holder assignment failed with HTTP ${status}: ${statusText}`,
- );
+ return { success: false, reason: 'OTHER', status, statusText };
}
+
+ return { success: true };
}
-async function upload(blob: Blob, params: BlobDescriptor): Promise<void> {
+async function upload(
+ blob: Blob,
+ params: BlobDescriptor,
+): Promise<
+ | {
+ +success: true,
+ }
+ | {
+ +success: false,
+ +assignHolderResult: BlobOperationResult,
+ +uploadBlobResult: BlobOperationResult,
+ },
+> {
const { hash, holder } = params;
- try {
- await Promise.all([assignHolder({ hash, holder }), uploadBlob(blob, hash)]);
- } catch (e) {
- throw new Error(
- `Payload upload failed with: ${
- getMessageForException(e) ?? 'unknown error'
- }`,
- );
+
+ const [holderResult, uploadResult] = await Promise.all([
+ assignHolder({ hash, holder }),
+ uploadBlob(blob, hash),
+ ]);
+ if (holderResult.success && uploadResult.success) {
+ return { success: true };
}
+ return {
+ success: false,
+ assignHolderResult: holderResult,
+ uploadBlobResult: uploadResult,
+ };
}
export type BlobDownloadResult =
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 8, 7:30 AM (6 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2440416
Default Alt Text
D10131.diff (2 KB)
Attached To
Mode
D10131: [keyserver] Change blob upload functions to return more usable results
Attached
Detach File
Event Timeline
Log In to Comment