Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 1620606

Browse files
authored
Fix IPFS upload failed error (#521)
* Fix IPFS upload failed error * Add checking on IPFS cid
1 parent 02f13c7 commit 1620606

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/core/uploaders/pinata-uploader.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ export class PinataUploader implements IStorageUpload {
7070
if (!res.ok) {
7171
throw new UploadError("Failed to upload files to IPFS");
7272
}
73+
74+
const cid = body.IpfsHash;
75+
if (!cid) {
76+
throw new UploadError("Failed to upload files to IPFS");
77+
}
78+
7379
return {
74-
cid: body.IpfsHash,
80+
cid,
7581
fileNames,
7682
};
7783
} else {
@@ -81,8 +87,17 @@ export class PinataUploader implements IStorageUpload {
8187
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
8288

8389
xhr.onloadend = () => {
90+
if (xhr.status !== 200) {
91+
throw new UploadError("Failed to upload files to IPFS");
92+
}
93+
94+
const cid = JSON.parse(xhr.responseText).IpfsHash;
95+
if (!cid) {
96+
throw new UploadError("Failed to upload files to IPFS");
97+
}
98+
8499
resolve({
85-
cid: JSON.parse(xhr.responseText).IpfsHash,
100+
cid,
86101
fileNames,
87102
});
88103
};

0 commit comments

Comments
 (0)