Wrap avatar fetch in try catch

pull/21833/head
Jaiwanth 2021-06-28 12:39:05 +05:30
parent 64b683a0df
commit 00ee3efbff
1 changed files with 17 additions and 9 deletions

View File

@ -42,10 +42,14 @@ export default class HTMLExporter extends Exporter {
const avatarUrl = Avatar.avatarUrlForRoom(this.room, 32, 32, "crop");
const avatarPath = "room.png";
if (avatarUrl) {
const image = await fetch(avatarUrl);
blob = await image.blob();
this.totalSize += blob.size;
this.addFile(avatarPath, blob);
try {
const image = await fetch(avatarUrl);
blob = await image.blob();
this.totalSize += blob.size;
this.addFile(avatarPath, blob);
} catch (err) {
console.log("Failed to fetch room's avatar" + err);
}
}
const avatar = (
<BaseAvatar
@ -205,11 +209,15 @@ export default class HTMLExporter extends Exporter {
protected async saveAvatarIfNeeded(event: MatrixEvent) {
const member = event.sender;
if (!this.avatars.has(member.userId)) {
const avatarUrl = this.getAvatarURL(event);
this.avatars.set(member.userId, true);
const image = await fetch(avatarUrl);
const blob = await image.blob();
this.addFile(`users/${member.userId.replace(/:/g, '-')}.png`, blob);
try {
const avatarUrl = this.getAvatarURL(event);
this.avatars.set(member.userId, true);
const image = await fetch(avatarUrl);
const blob = await image.blob();
this.addFile(`users/${member.userId.replace(/:/g, '-')}.png`, blob);
} catch (err) {
console.log("Failed to fetch user's avatar" + err);
}
}
}