@@ -40,11 +40,25 @@ const service: LocalImageService = {
4040 let buffer = inputBuffer ;
4141
4242 if ( / ^ h t t p s ? : \/ \/ / . test ( transform . src ) ) {
43- const response = await fetch ( transform . src ) ;
44- if ( ! response . ok ) {
45- throw new Error ( `Failed to fetch image from ${ transform . src } ` ) ;
43+ try {
44+ const response = await fetch ( transform . src ) ;
45+ if ( ! response . ok ) {
46+ console . warn (
47+ `⚠️ Failed to fetch image: ${ transform . src } (status ${ response . status } )`
48+ ) ;
49+ return {
50+ data : buffer , // fallback to original input
51+ format : transform . format ?? ( "webp" as OutputFormat ) ,
52+ } ;
53+ }
54+ buffer = new Uint8Array ( await response . arrayBuffer ( ) ) ;
55+ } catch ( err ) {
56+ console . warn ( `⚠️ Error fetching image from ${ transform . src } :` , err ) ;
57+ return {
58+ data : buffer , // fallback to original input
59+ format : transform . format ?? ( "webp" as OutputFormat ) ,
60+ } ;
4661 }
47- buffer = new Uint8Array ( await response . arrayBuffer ( ) ) ;
4862 }
4963
5064 const sharp = ( await import ( "sharp" ) ) . default ;
@@ -62,12 +76,9 @@ const service: LocalImageService = {
6276
6377 const outputBuffer = await image . toBuffer ( ) ;
6478
65- // Convert Buffer to Uint8Array
66- const uint8Array = Uint8Array . from ( outputBuffer ) ;
67-
6879 return {
69- data : uint8Array ,
70- format : transform . format ?? ( "webp" as OutputFormat ) , // Adjust the format here
80+ data : Uint8Array . from ( outputBuffer ) ,
81+ format : transform . format ?? ( "webp" as OutputFormat ) ,
7182 } ;
7283 } ,
7384
0 commit comments