Improve MImageBody error handling (#9663)
* Improve MImageBody error handling * Fix strict errors * We can assert this as isAnimated would be false if no content.info.mimetypepull/28788/head^2
parent
7065c58174
commit
5f76528832
|
@ -270,6 +270,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
||||||
|
|
||||||
// Set a placeholder image when we can't decrypt the image.
|
// Set a placeholder image when we can't decrypt the image.
|
||||||
this.setState({ error });
|
this.setState({ error });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
thumbUrl = this.getThumbUrl();
|
thumbUrl = this.getThumbUrl();
|
||||||
|
@ -291,17 +292,28 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
||||||
img.crossOrigin = "Anonymous"; // CORS allow canvas access
|
img.crossOrigin = "Anonymous"; // CORS allow canvas access
|
||||||
img.src = contentUrl;
|
img.src = contentUrl;
|
||||||
|
|
||||||
|
try {
|
||||||
await loadPromise;
|
await loadPromise;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Unable to download attachment: ", error);
|
||||||
|
this.setState({ error: error as Error });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const blob = await this.props.mediaEventHelper.sourceBlob.value;
|
const blob = await this.props.mediaEventHelper.sourceBlob.value;
|
||||||
if (!await blobIsAnimated(content.info.mimetype, blob)) {
|
if (!await blobIsAnimated(content.info?.mimetype, blob)) {
|
||||||
isAnimated = false;
|
isAnimated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAnimated) {
|
if (isAnimated) {
|
||||||
const thumb = await createThumbnail(img, img.width, img.height, content.info.mimetype, false);
|
const thumb = await createThumbnail(img, img.width, img.height, content.info!.mimetype, false);
|
||||||
thumbUrl = URL.createObjectURL(thumb.thumbnail);
|
thumbUrl = URL.createObjectURL(thumb.thumbnail);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// This is a non-critical failure, do not surface the error or bail the method here
|
||||||
|
logger.warn("Unable to generate thumbnail for animated image: ", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue