Fix possible uncaught exception for getUrlPreview which would cause 0 url previews if one url was faulty
This commit is contained in:
parent
1eaf6dd4ed
commit
e9d56d4f13
1 changed files with 5 additions and 3 deletions
|
@ -40,10 +40,12 @@ const LinkPreviewGroup: React.FC<IProps> = ({ links, mxEvent, onCancelClick, onH
|
||||||
|
|
||||||
const ts = mxEvent.getTs();
|
const ts = mxEvent.getTs();
|
||||||
const previews = useAsyncMemo<[string, IPreviewUrlResponse][]>(async () => {
|
const previews = useAsyncMemo<[string, IPreviewUrlResponse][]>(async () => {
|
||||||
return Promise.all<[string, IPreviewUrlResponse] | void>(links.map(link => {
|
return Promise.all<[string, IPreviewUrlResponse] | void>(links.map(async link => {
|
||||||
return cli.getUrlPreview(link, ts).then(preview => [link, preview], error => {
|
try {
|
||||||
|
return [link, await cli.getUrlPreview(link, ts)];
|
||||||
|
} catch (error) {
|
||||||
console.error("Failed to get URL preview: " + error);
|
console.error("Failed to get URL preview: " + error);
|
||||||
});
|
}
|
||||||
})).then(a => a.filter(Boolean)) as Promise<[string, IPreviewUrlResponse][]>;
|
})).then(a => a.filter(Boolean)) as Promise<[string, IPreviewUrlResponse][]>;
|
||||||
}, [links, ts], []);
|
}, [links, ts], []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue