Repository: anuraghazra/github-readme-stats
Pull request #3100 (2023-08-19 02:32:25)

Gist card: handle not found error

vercel[bot]: [vc]: #lQ5uW3KlExv9se65ItBhhgZfKHeoR/IA+ky1o4+JIVs=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJnaXRodWItcmVhZG1lLXN0YXRzIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2dpdGh1Yi1yZWFkbWUtc3RhdHMtdGVhbS9naXRodWItcmVhZG1lLXN0YXRzL0dGTldqVmk0RVRXWlJtalRmbm8zdTF4THhhNDMiLCJwcmV2aWV3VXJsIjoiZ2l0aHViLXJlYWRtZS1zdGF0cy1naXQtZ2lzdGNhci1iZDNmMzQtZ2l0aHViLXJlYWRtZS1zdGF0cy10ZWFtLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| **github-readme-stats** | ✅ Ready ([Inspect](https://vercel.com/github-readme-stats-team/github-readme-stats/GFNWjVi4ETWZRmjTfno3u1xLxa43)) | [Visit Preview](https://github-readme-stats-git-gistcar-bd3f34-github-readme-stats-team.vercel.app) | Aug 19, 2023 2:32am |


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3100?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) Report
Patch coverage: **`100.00%`** and no project coverage change.
> Comparison is base [(`ea79314`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/commit/ea79314a853ea5480127f646f6ad8cd70d5997bc?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.67% compared to head [(`9d82a19`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3100?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.67%.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #3100   +/-   ##
=======================================
  Coverage   97.67%   97.67%           
=======================================
  Files          27       27           
  Lines        5810     5811    +1     
  Branches      499      500    +1     
=======================================
+ Hits         5675     5676    +1     
  Misses        133      133           
  Partials        2        2           
```


| [Files Changed](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3100?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) | Coverage Δ | |
|---|---|---|
| [src/fetchers/gist-fetcher.js](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3100?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra#diff-c3JjL2ZldGNoZXJzL2dpc3QtZmV0Y2hlci5qcw==) | `97.19% <100.00%> (+0.02%)` | :arrow_up: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3100?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra).


Patch:
diff --git a/readme.md b/readme.md
index caffaca..ada6af1 100644
--- a/readme.md
+++ b/readme.md
@@ -282,7 +282,7 @@ You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-1
 
 ### Customization
 
-You can customize the appearance of your `Stats Card` or `Repo Card` however you wish with URL parameters.
+You can customize the appearance of all your cards however you wish with URL parameters.
 
 #### Common Options
 
diff --git a/src/fetchers/gist-fetcher.js b/src/fetchers/gist-fetcher.js
index 8e1eb75..9ede43f 100644
--- a/src/fetchers/gist-fetcher.js
+++ b/src/fetchers/gist-fetcher.js
@@ -60,6 +60,7 @@ const fetchGist = async (id) => {
   if (!id) throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
   const res = await retryer(fetcher, { gistName: id });
   if (res.data.errors) throw new Error(res.data.errors[0].message);
+  if (!res.data.data.viewer.gist) throw new Error("Gist not found");
   const data = res.data.data.viewer.gist;
   return {
     name: data.files[Object.keys(data.files)[0]].name,


Test patch:
diff --git a/tests/fetchGist.test.js b/tests/fetchGist.test.js
index da045b0..13c29a8 100644
--- a/tests/fetchGist.test.js
+++ b/tests/fetchGist.test.js
@@ -25,12 +25,41 @@ const gist_data = {
             },
             size: 85858,
           },
+          {
+            name: "territories.txt",
+            language: {
+              name: "Text",
+            },
+            size: 87858,
+          },
+          {
+            name: "countries_spanish.json",
+            language: {
+              name: "JSON",
+            },
+            size: 85858,
+          },
+          {
+            name: "territories_spanish.txt",
+            language: {
+              name: "Text",
+            },
+            size: 87858,
+          },
         ],
       },
     },
   },
 };
 
+const gist_not_found_data = {
+  data: {
+    viewer: {
+      gist: null,
+    },
+  },
+};
+
 const gist_errors_data = {
   errors: [
     {
@@ -56,12 +85,22 @@ describe("Test fetchGist", () => {
       nameWithOwner: "Yizack/countries.json",
       description:
         "List of countries and territories in English and Spanish: name, continent, capital, dial code, country codes, TLD, and area in sq km. Lista de países y territorios en Inglés y Español: nombre, continente, capital, código de teléfono, códigos de país, dominio y área en km cuadrados. Updated 2023",
-      language: "JSON",
+      language: "Text",
       starsCount: 33,
       forksCount: 11,
     });
   });
 
+  it("should throw correct error if gist not found", async () => {
+    mock
+      .onPost("https://api.github.com/graphql")
+      .reply(200, gist_not_found_data);
+
+    await expect(fetchGist("bbfce31e0217a3689c8d961a356cb10d")).rejects.toThrow(
+      "Gist not found",
+    );
+  });
+
   it("should throw error if reaponse contains them", async () => {
     mock.onPost("https://api.github.com/graphql").reply(200, gist_errors_data);