import type { ResponseHeaders } from "@octokit/types"; import type { GraphQlEndpointOptions, GraphQlQueryResponse } from "./types.js"; type ServerResponseData = Required>; function _buildMessageForResponseErrors( data: ServerResponseData, ): string { return ( `Request failed due to following response errors:\n` + data.errors.map((e) => ` - ${e.message}`).join("\n") ); } export class GraphqlResponseError extends Error { override name = "GraphqlResponseError"; readonly errors: GraphQlQueryResponse["errors"]; readonly data: ResponseData; constructor( readonly request: GraphQlEndpointOptions, readonly headers: ResponseHeaders, readonly response: ServerResponseData, ) { super(_buildMessageForResponseErrors(response)); // Expose the errors and response data in their shorthand properties. this.errors = response.errors; this.data = response.data; // Maintains proper stack trace (only available on V8) /* istanbul ignore next */ if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } }