throw an error rather than returning null on link preview failure

so that it is handled in the catch() block
pull/1387/head
Audric Ackermann 5 years ago
parent ba959f3379
commit 1541b47f13
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -290,7 +290,7 @@ export class SessionCompositionBox extends React.Component<Props, State> {
const { ignoredLink } = this.state; const { ignoredLink } = this.state;
// Don't render link previews if quoted message or attachments are already added // 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 <></>; return <></>;
} }
// we try to match the first link found in the current message // we try to match the first link found in the current message

@ -34,7 +34,7 @@ export const getPreview = async (
): Promise<null | GetLinkPreviewResult> => { ): Promise<null | GetLinkPreviewResult> => {
// This is already checked elsewhere, but we want to be extra-careful. // This is already checked elsewhere, but we want to be extra-careful.
if (!window.Signal.LinkPreviews.isLinkSafeToPreview(url)) { if (!window.Signal.LinkPreviews.isLinkSafeToPreview(url)) {
return null; throw new Error('Link not safe for preview');
} }
const linkPreviewMetadata = await LinkPreviewUtil.fetchLinkPreviewMetadata( const linkPreviewMetadata = await LinkPreviewUtil.fetchLinkPreviewMetadata(
@ -43,7 +43,7 @@ export const getPreview = async (
abortSignal abortSignal
); );
if (!linkPreviewMetadata) { if (!linkPreviewMetadata) {
return null; throw new Error('Could not fetch link preview metadata');
} }
const { title, imageHref, description, date } = linkPreviewMetadata; const { title, imageHref, description, date } = linkPreviewMetadata;

Loading…
Cancel
Save