From 1541b47f13ab9115eb21fdbb95b1efa41aac7f02 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 28 Oct 2020 13:40:30 +1100 Subject: [PATCH] throw an error rather than returning null on link preview failure so that it is handled in the catch() block --- ts/components/session/conversation/SessionCompositionBox.tsx | 2 +- .../session/conversation/SessionStagedLinkPreview.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ts/components/session/conversation/SessionCompositionBox.tsx b/ts/components/session/conversation/SessionCompositionBox.tsx index 200b73e6c..c54a85729 100644 --- a/ts/components/session/conversation/SessionCompositionBox.tsx +++ b/ts/components/session/conversation/SessionCompositionBox.tsx @@ -290,7 +290,7 @@ export class SessionCompositionBox extends React.Component { const { ignoredLink } = this.state; // Don't render link previews if quoted message or attachments are already added - if (stagedAttachments.length !== 0 && quotedMessageProps?.id) { + if (stagedAttachments.length !== 0 || quotedMessageProps?.id) { return <>; } // we try to match the first link found in the current message diff --git a/ts/components/session/conversation/SessionStagedLinkPreview.tsx b/ts/components/session/conversation/SessionStagedLinkPreview.tsx index 9e48b1b63..326a6c69d 100644 --- a/ts/components/session/conversation/SessionStagedLinkPreview.tsx +++ b/ts/components/session/conversation/SessionStagedLinkPreview.tsx @@ -34,7 +34,7 @@ export const getPreview = async ( ): Promise => { // This is already checked elsewhere, but we want to be extra-careful. if (!window.Signal.LinkPreviews.isLinkSafeToPreview(url)) { - return null; + throw new Error('Link not safe for preview'); } const linkPreviewMetadata = await LinkPreviewUtil.fetchLinkPreviewMetadata( @@ -43,7 +43,7 @@ export const getPreview = async ( abortSignal ); if (!linkPreviewMetadata) { - return null; + throw new Error('Could not fetch link preview metadata'); } const { title, imageHref, description, date } = linkPreviewMetadata;