File tree Expand file tree Collapse file tree
packages/script/src/runtime/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -355,7 +355,11 @@ export default defineEventHandler(async (event) => {
355355 log ( '[proxy] Fetching:' , targetUrl )
356356
357357 const controller = new AbortController ( )
358- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 15000 ) // 15s timeout
358+ let timedOut = false
359+ const timeoutId = setTimeout ( ( ) => {
360+ timedOut = true
361+ controller . abort ( )
362+ } , 15000 ) // 15s timeout
359363
360364 // Resolve the fetch body: passthrough streams the raw request, otherwise serialize
361365 let fetchBody : BodyInit | undefined
@@ -381,9 +385,14 @@ export default defineEventHandler(async (event) => {
381385 catch ( err ) {
382386 log ( '[proxy] Upstream error:' , err )
383387 throw createError ( {
384- statusCode : 502 ,
385- statusMessage : 'Bad Gateway' ,
388+ statusCode : timedOut ? 504 : 502 ,
389+ statusMessage : timedOut ? 'Gateway Timeout' : 'Bad Gateway' ,
386390 message : `Proxy upstream request failed: ${ targetUrl } ` ,
391+ cause : err ,
392+ data : {
393+ errorName : ( err as Error ) ?. name ,
394+ errorCode : timedOut ? 'TIMEOUT' : ( err as { code ?: string } ) ?. code ,
395+ } ,
387396 } )
388397 }
389398 finally {
You can’t perform that action at this time.
0 commit comments