Skip to content

Commit

Permalink
fix: Catch preflight errors on file upload (#212)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mertkirbuga and Mert Kirbuga authored Mar 8, 2024
1 parent b9e690d commit c535587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ export class Session<
},
});

uploader.start();
uploader.start().catch(reject);
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion source/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ export class Uploader<TEntityTypeMap extends Record<string, any>> {
/** Initiate upload. Promise is resolved once preflight is complete and upload started. */
async start() {
logger.debug("Upload starting", this.componentId);
await this.uploadPreflight();
try {
await this.uploadPreflight();
} catch (error) {
if (this.onError) {
this.onError(error as Error);
}
throw error;
}
if (!this.uploadMetadata) {
throw new Error("Failed to get upload metadata");
}
Expand Down

0 comments on commit c535587

Please sign in to comment.