Differentiate download and decryption errors when showing images (#9562)

This commit is contained in:
Michael Telatynski 2022-11-10 09:27:20 +00:00 committed by GitHub
parent abec724387
commit 962e8e0b23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 170 additions and 133 deletions

View file

@ -39,6 +39,7 @@ import { blobIsAnimated, mayBeAnimated } from '../../../utils/Image';
import { presentableTextForFile } from "../../../utils/FileUtils";
import { createReconnectedListener } from '../../../utils/connection';
import MediaProcessingError from './shared/MediaProcessingError';
import { DecryptError, DownloadError } from "../../../utils/DecryptFile";
enum Placeholder {
NoImage,
@ -258,7 +259,15 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
]));
} catch (error) {
if (this.unmounted) return;
logger.warn("Unable to decrypt attachment: ", error);
if (error instanceof DecryptError) {
logger.error("Unable to decrypt attachment: ", error);
} else if (error instanceof DownloadError) {
logger.error("Unable to download attachment to decrypt it: ", error);
} else {
logger.error("Error encountered when downloading encrypted attachment: ", error);
}
// Set a placeholder image when we can't decrypt the image.
this.setState({ error });
}
@ -557,9 +566,16 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
const content = this.props.mxEvent.getContent<IMediaEventContent>();
if (this.state.error) {
let errorText = _t("Unable to show image due to error");
if (this.state.error instanceof DecryptError) {
errorText = _t("Error decrypting image");
} else if (this.state.error instanceof DownloadError) {
errorText = _t("Error downloading image");
}
return (
<MediaProcessingError className="mx_MImageBody">
{ _t("Error decrypting image") }
{ errorText }
</MediaProcessingError>
);
}