@@ -284,20 +284,42 @@ class BaseClient {
284
284
) ,
285
285
} ) ;
286
286
287
- if ( res . status === 200 ) {
288
- const json = await res . json ( ) ;
289
- debug ( '_doRequest.response' , { status : res . status , errors : json . errors } ) ;
290
-
291
- if ( Array . isArray ( json . errors ) && json . errors . length ) {
292
- const err = new Error ( `GraphQLError: ${ json . errors . map ( x => x . message ) . join ( '; ' ) } ` ) ;
293
- err . errors = json . errors ;
294
- throw err ;
287
+ let json ;
288
+ try {
289
+ json = await res . json ( ) ;
290
+ debug ( '_doRequest.response' , { status : res . status , errors : json ? json . errors : undefined } ) ;
291
+ } catch ( err ) {
292
+ json = { } ;
293
+ }
294
+
295
+ // Handle GraphQL errors regardless of HTTP status
296
+ if ( Array . isArray ( json . errors ) && json . errors . length ) {
297
+ const errorMessages = json . errors . map ( x => x . message ) ;
298
+ const hasSchemaError = errorMessages . some ( msg => msg . includes ( 'Cannot query field' ) ) ;
299
+
300
+ let message = errorMessages . join ( '\n' ) ;
301
+ if ( hasSchemaError ) {
302
+ message = `Schema Compatibility Error: ${ message } \nThis error typically indicates you are using an incompatible GraphQL client version. Please ensure your client version matches the server schema version.` ;
303
+ } else {
304
+ message = `GraphQLError: ${ message } ` ;
295
305
}
296
306
297
- return dataKey && json . data [ dataKey ] ? json . data [ dataKey ] : json . data ;
307
+ const err = new Error ( message ) ;
308
+ err . errors = json . errors ;
309
+ err . status = res . status ;
310
+ throw err ;
311
+ }
312
+
313
+ // Handle HTTP errors
314
+ if ( res . status !== 200 ) {
315
+ const message = json . error || json . message || `GraphQL Status Error ${ res . status } ` ;
316
+ const err = new Error ( message ) ;
317
+ err . status = res . status ;
318
+ err . response = json ;
319
+ throw err ;
298
320
}
299
321
300
- throw new Error ( `GraphQL Status Error ${ res . status } ` ) ;
322
+ return dataKey && json . data [ dataKey ] ? json . data [ dataKey ] : json . data ;
301
323
}
302
324
303
325
/**
@@ -491,4 +513,3 @@ class BaseClient {
491
513
}
492
514
493
515
module . exports = BaseClient ;
494
- //# sourceMappingURL=index.js.map
0 commit comments