fix: handle errors from Iframely
This commit is contained in:
@@ -93,7 +93,7 @@ function HoverPreviewInternal({ element, onClose }: Props) {
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const card = cardRef.current;
|
const card = cardRef.current;
|
||||||
|
|
||||||
if (data) {
|
if (data && !data.error) {
|
||||||
startOpenTimer();
|
startOpenTimer();
|
||||||
|
|
||||||
if (card) {
|
if (card) {
|
||||||
@@ -134,7 +134,7 @@ function HoverPreviewInternal({ element, onClose }: Props) {
|
|||||||
return <LoadingIndicator />;
|
return <LoadingIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data || data.error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
import { Unfurl } from "@shared/types";
|
import { IframelyErrorResponse, Unfurl } from "@shared/types";
|
||||||
|
|
||||||
function presentUnfurl(data: any): Unfurl {
|
function presentUnfurl(data: any): Unfurl | IframelyErrorResponse {
|
||||||
return {
|
return !data.error
|
||||||
|
? {
|
||||||
url: data.url,
|
url: data.url,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
thumbnailUrl: data.thumbnail_url,
|
thumbnailUrl: data.thumbnail_url,
|
||||||
meta: data.meta,
|
meta: data.meta,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
status: data.status,
|
||||||
|
error: data.error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await Iframely.unfurl(url);
|
const data = await Iframely.unfurl(url);
|
||||||
|
if (data.error) {
|
||||||
|
ctx.response.status = data.status;
|
||||||
|
}
|
||||||
ctx.body = presentUnfurl(data);
|
ctx.body = presentUnfurl(data);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -225,5 +225,10 @@ export type Unfurl<T = OEmbedType> = {
|
|||||||
meta?: Record<string, string>;
|
meta?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IframelyErrorResponse = {
|
||||||
|
status: number;
|
||||||
|
error: string;
|
||||||
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export type ProsemirrorData = Record<string, any>;
|
export type ProsemirrorData = Record<string, any>;
|
||||||
|
|||||||
Reference in New Issue
Block a user