Skip to content

Commit c535587

Browse files
mertkirbugaMert Kirbuga
andauthored
fix: Catch preflight errors on file upload (#212)
* Catch preflight errors on js api * ts error fix * Throw error instead of return statement * Add second reaction for uploader --------- Co-authored-by: Mert Kirbuga <mert.kirbuga@backlight.co>
1 parent b9e690d commit c535587

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

source/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ export class Session<
10921092
},
10931093
});
10941094

1095-
uploader.start();
1095+
uploader.start().catch(reject);
10961096
});
10971097
}
10981098
}

source/uploader.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ export class Uploader<TEntityTypeMap extends Record<string, any>> {
177177
/** Initiate upload. Promise is resolved once preflight is complete and upload started. */
178178
async start() {
179179
logger.debug("Upload starting", this.componentId);
180-
await this.uploadPreflight();
180+
try {
181+
await this.uploadPreflight();
182+
} catch (error) {
183+
if (this.onError) {
184+
this.onError(error as Error);
185+
}
186+
throw error;
187+
}
181188
if (!this.uploadMetadata) {
182189
throw new Error("Failed to get upload metadata");
183190
}

0 commit comments

Comments
 (0)