@pratik7368patil/anchor-core 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6260,9 +6260,29 @@ function errorMessage(status, errors) {
6260
6260
  if (messages.length > 0) return messages.join("; ");
6261
6261
  return `GitHub GraphQL request failed with status ${status}.`;
6262
6262
  }
6263
+ function responsePreview(text) {
6264
+ return text.replace(/\s+/g, " ").trim().slice(0, 120);
6265
+ }
6266
+ function parseGraphQLResponse(text, status, headers) {
6267
+ try {
6268
+ return JSON.parse(text);
6269
+ } catch {
6270
+ const contentType = String(headers["content-type"] ?? "unknown");
6271
+ const preview = responsePreview(text);
6272
+ throw new GitHubGraphQLError(
6273
+ `GitHub GraphQL returned a non-JSON response with status ${status} and content-type ${contentType}.${preview ? ` Response preview: ${preview}` : ""}`,
6274
+ {
6275
+ status,
6276
+ headers
6277
+ }
6278
+ );
6279
+ }
6280
+ }
6263
6281
  function createGitHubGraphQLRequester(options) {
6264
6282
  if (!options.token.trim()) {
6265
- throw new Error("GitHub authentication is required. Run gh auth login, or export GITHUB_TOKEN/GH_TOKEN.");
6283
+ throw new Error(
6284
+ "GitHub authentication is required. Run gh auth login, or export GITHUB_TOKEN/GH_TOKEN."
6285
+ );
6266
6286
  }
6267
6287
  const fetchImpl = options.fetchImpl ?? globalThis.fetch;
6268
6288
  if (!fetchImpl) throw new Error("Global fetch is unavailable in this Node.js runtime.");
@@ -6280,7 +6300,7 @@ function createGitHubGraphQLRequester(options) {
6280
6300
  body: JSON.stringify({ query, variables })
6281
6301
  });
6282
6302
  const headers = headersToRecord(response.headers);
6283
- const raw = await response.json();
6303
+ const raw = parseGraphQLResponse(await response.text(), response.status, headers);
6284
6304
  if (!response.ok || raw.errors?.length) {
6285
6305
  throw new GitHubGraphQLError(errorMessage(response.status, raw.errors), {
6286
6306
  status: errorStatus(response.status, raw.errors),
@@ -7198,7 +7218,8 @@ function createProgressRateLimitController(repo, onProgress) {
7198
7218
  };
7199
7219
  }
7200
7220
  function shouldFallbackToRestAfterGraphQLError(error) {
7201
- return !isGitHubRateLimitError(error) && !isGitHubGraphQLResourceLimitError(error);
7221
+ const message = (error.message ?? "").toLowerCase();
7222
+ return !isGitHubRateLimitError(error) && !isGitHubGraphQLResourceLimitError(error) && !message.includes("non-json response");
7202
7223
  }
7203
7224
  async function fetchPullRequestDetailsConcurrently(options) {
7204
7225
  const results = new Array(options.pullNumbers.length);
@@ -7329,7 +7350,10 @@ async function fetchMergedPullRequests(options) {
7329
7350
  options.repo,
7330
7351
  options.onProgress
7331
7352
  );
7332
- const restRateLimitController = createProgressRateLimitController(options.repo, options.onProgress);
7353
+ const restRateLimitController = createProgressRateLimitController(
7354
+ options.repo,
7355
+ options.onProgress
7356
+ );
7333
7357
  try {
7334
7358
  return await fetchMergedPullRequestsWithGraphQL({
7335
7359
  token: options.token,