diff --git a/app/components/HoverPreview/HoverPreview.tsx b/app/components/HoverPreview/HoverPreview.tsx index da68fed4c..94224e900 100644 --- a/app/components/HoverPreview/HoverPreview.tsx +++ b/app/components/HoverPreview/HoverPreview.tsx @@ -93,7 +93,7 @@ function HoverPreviewInternal({ element, onClose }: Props) { React.useEffect(() => { const card = cardRef.current; - if (data) { + if (data && !data.error) { startOpenTimer(); if (card) { @@ -134,7 +134,7 @@ function HoverPreviewInternal({ element, onClose }: Props) { return ; } - if (!data) { + if (!data || data.error) { return null; } diff --git a/server/presenters/unfurls/unfurl.ts b/server/presenters/unfurls/unfurl.ts index 6d8e6d654..8e8c3f3f7 100644 --- a/server/presenters/unfurls/unfurl.ts +++ b/server/presenters/unfurls/unfurl.ts @@ -1,14 +1,19 @@ -import { Unfurl } from "@shared/types"; +import { IframelyErrorResponse, Unfurl } from "@shared/types"; -function presentUnfurl(data: any): Unfurl { - return { - url: data.url, - type: data.type, - title: data.title, - description: data.description, - thumbnailUrl: data.thumbnail_url, - meta: data.meta, - }; +function presentUnfurl(data: any): Unfurl | IframelyErrorResponse { + return !data.error + ? { + url: data.url, + type: data.type, + title: data.title, + description: data.description, + thumbnailUrl: data.thumbnail_url, + meta: data.meta, + } + : { + status: data.status, + error: data.error, + }; } export default presentUnfurl; diff --git a/server/routes/api/urls/urls.ts b/server/routes/api/urls/urls.ts index 37f57d4b4..9e90112e4 100644 --- a/server/routes/api/urls/urls.ts +++ b/server/routes/api/urls/urls.ts @@ -63,6 +63,9 @@ router.post( } const data = await Iframely.unfurl(url); + if (data.error) { + ctx.response.status = data.status; + } ctx.body = presentUnfurl(data); } ); diff --git a/shared/types.ts b/shared/types.ts index a01325862..3968277e7 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -225,5 +225,10 @@ export type Unfurl = { meta?: Record; }; +export type IframelyErrorResponse = { + status: number; + error: string; +}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any export type ProsemirrorData = Record;