From e2fb0c4ff29d27bbd39193127c64fd4f312129e3 Mon Sep 17 00:00:00 2001 From: wulinsheng123 <409187100@qq.com> Date: Thu, 17 Nov 2022 05:55:48 +0800 Subject: [PATCH] Log error if failed to fetch remote image (#5393) * I cant catch an error in the loadRemoteImage function when the fetch function occurs error * I cant catch an error in the loadRemoteImage function when the fetch function occurs error * fix ssg file Co-authored-by: wuls Co-authored-by: Okiki Ojo --- .changeset/tough-doors-shop.md | 5 +++++ packages/integrations/image/src/build/ssg.ts | 3 ++- packages/integrations/image/src/endpoint.ts | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/tough-doors-shop.md diff --git a/.changeset/tough-doors-shop.md b/.changeset/tough-doors-shop.md new file mode 100644 index 000000000..738561466 --- /dev/null +++ b/.changeset/tough-doors-shop.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Log error if failed to fetch remote image diff --git a/packages/integrations/image/src/build/ssg.ts b/packages/integrations/image/src/build/ssg.ts index 2382797c1..9a18b1a70 100644 --- a/packages/integrations/image/src/build/ssg.ts +++ b/packages/integrations/image/src/build/ssg.ts @@ -73,7 +73,8 @@ async function loadRemoteImage(src: string) { data: Buffer.from(await res.arrayBuffer()), expires: Date.now() + expires, }; - } catch { + } catch (err: unknown) { + console.error(err) return undefined; } } diff --git a/packages/integrations/image/src/endpoint.ts b/packages/integrations/image/src/endpoint.ts index 872403226..06599a7ea 100644 --- a/packages/integrations/image/src/endpoint.ts +++ b/packages/integrations/image/src/endpoint.ts @@ -14,7 +14,8 @@ async function loadRemoteImage(src: URL) { } return Buffer.from(await res.arrayBuffer()); - } catch { + } catch (err: unknown) { + console.error(err) return undefined; } }