File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,10 +29,20 @@ async function request<T = unknown>(
2929 }
3030 const res = await fetch ( `${ BASE } ${ path } ` , opts ) ;
3131 const text = await res . text ( ) ;
32- const data = text ? ( JSON . parse ( text ) as unknown ) : null ;
32+ let data : unknown = null ;
33+ try {
34+ data = text ? JSON . parse ( text ) : null ;
35+ } catch {
36+ // Non-JSON body (e.g. HTML error page from the dev proxy or a crashed
37+ // backend). Surface the HTTP status + a snippet so it's actually
38+ // debuggable instead of a bare SyntaxError from JSON.parse.
39+ throw new Error (
40+ `${ method } ${ path } → ${ res . status } ${ res . statusText } : ${ text . slice ( 0 , 200 ) } ` ,
41+ ) ;
42+ }
3343 if ( ! res . ok ) {
3444 const msg = ( data as { error ?: string } | null ) ?. error ?? res . statusText ;
35- throw new Error ( msg ) ;
45+ throw new Error ( ` ${ method } ${ path } → ${ res . status } : ${ msg } ` ) ;
3646 }
3747 return data as T ;
3848}
You can’t perform that action at this time.
0 commit comments