import type { ClientError , GraphQLRequestContext , GraphQLResponse } from 'graphql-request/dist/types' ; import { DetailsError } from './DetailsError' ; export class GQLError extends DetailsError { response : GraphQLResponse ; request : GraphQLRequestContext ; errorMessage : string ; errorCode ? : string ; isTextBody = false ; constructor ( clientError ) { super ( clientError . message ) ; this . name = 'Server Error' ; this . response = clientError . response ; this . request = clientError . request ; if ( typeof clientError . response . error === 'string' ) { this . isTextBody = true ; this . errorMessage = clientError . response . error ; } else { this . errorMessage = clientError . response . errors ?. map ( e => e . message ) . join ( '\n' ) || 'unknown error' ; const firstError = clientError . response . errors ?. [ 0 ] ; this . errorCode = firstError ?. extensions ?. webErrorCode ; } } hasDetails ( ) { return this . response . errors ?. some ( error => ! ! error . extensions ) || false ; } }