@@ -81,7 +81,12 @@ export async function request<T>(url: string, options: RequestOptions = {}) {
8181 try {
8282 response = await fetch ( fullUrl , opts ) ;
8383 } catch ( error : any ) {
84- if ( error . message . toLowerCase ( ) . includes ( 'failed to fetch' ) ) {
84+ const errorMsg = error . message . toLowerCase ( ) ;
85+
86+ if (
87+ errorMsg . includes ( 'failed to fetch' ) || // Chrome
88+ errorMsg . includes ( 'networkerror when attempting to fetch resource' ) // Firefox
89+ ) {
8590 throw new Error (
8691 'Request failed due to a connectivity issue. Please check your network connection.' ,
8792 ) ;
@@ -95,12 +100,19 @@ export async function request<T>(url: string, options: RequestOptions = {}) {
95100
96101 const responseClone = response . clone ( ) ;
97102
98- if ( contentType && contentType . includes ( 'application/json' ) ) {
99- responseBody = await response . json ( ) ;
100- } else if ( contentType ?. includes ( 'multipart/form-data' ) && response . body ) {
101- responseBody = await parseMultipart ( response ) ;
102- } else {
103- responseBody = await response . text ( ) ;
103+ try {
104+ if ( contentType && contentType . includes ( 'application/json' ) ) {
105+ responseBody = await response . json ( ) ;
106+ } else if ( contentType ?. includes ( 'multipart/form-data' ) && response . body ) {
107+ responseBody = await parseMultipart ( response ) ;
108+ } else {
109+ responseBody = await response . text ( ) ;
110+ }
111+ } catch ( error : any ) {
112+ const err = new Error ( 'Failed to read server response.' ) ;
113+ ( err as any ) . cause = error ;
114+
115+ throw err ;
104116 }
105117
106118 if ( options . onResponse ) {
0 commit comments