Repository: anuraghazra/github-readme-stats
Pull request #3101 (2023-08-19 02:50:14)

Gist card: handle missing param error

vercel[bot]: [vc]: #wBk0qVM15QG7AxDeQFtjVaeGCxXC+IxwVYuM2HSmupw=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJnaXRodWItcmVhZG1lLXN0YXRzIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2dpdGh1Yi1yZWFkbWUtc3RhdHMtdGVhbS9naXRodWItcmVhZG1lLXN0YXRzLzJmYUFYTW83U0NHVnpVZTFpZ3d4TmRTUDFjVGQiLCJwcmV2aWV3VXJsIjoiZ2l0aHViLXJlYWRtZS1zdGF0cy1naXQtZ2lzdGNhci03ZDQyZjgtZ2l0aHViLXJlYWRtZS1zdGF0cy10ZWFtLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV19
**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/2faAXMo7SCGVzUe1igwxNdSP1cTd)) | [Visit Preview](https://github-readme-stats-git-gistcar-7d42f8-github-readme-stats-team.vercel.app) | Aug 19, 2023 2:50am |


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3101?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 [(`fd09b10`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3101?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    #3101   +/-   ##
=======================================
  Coverage   97.67%   97.67%           
=======================================
  Files          27       27           
  Lines        5810     5811    +1     
  Branches      499      501    +2     
=======================================
+ Hits         5675     5676    +1     
  Misses        133      133           
  Partials        2        2           
```


| [Files Changed](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3101?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/3101?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/3101?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/src/fetchers/gist-fetcher.js b/src/fetchers/gist-fetcher.js
index 2afc62a..8e1eb75 100644
--- a/src/fetchers/gist-fetcher.js
+++ b/src/fetchers/gist-fetcher.js
@@ -1,6 +1,6 @@
 // @ts-check
 
-import { request } from "../common/utils.js";
+import { request, MissingParamError } from "../common/utils.js";
 import { retryer } from "../common/retryer.js";
 
 /**
@@ -57,6 +57,7 @@ const fetcher = async (variables, token) => {
  * @returns {Promise<GistData>} Gist data.
  */
 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);
   const data = res.data.data.viewer.gist;


Test patch:
diff --git a/tests/fetchGist.test.js b/tests/fetchGist.test.js
index 2cdffcf..da045b0 100644
--- a/tests/fetchGist.test.js
+++ b/tests/fetchGist.test.js
@@ -69,4 +69,10 @@ describe("Test fetchGist", () => {
       "Some test GraphQL error",
     );
   });
+
+  it("should throw error if id is not provided", async () => {
+    await expect(fetchGist()).rejects.toThrow(
+      'Missing params "id" make sure you pass the parameters in URL',
+    );
+  });
 });
diff --git a/tests/gist.test.js b/tests/gist.test.js
index 1413229..985ad6c 100644
--- a/tests/gist.test.js
+++ b/tests/gist.test.js
@@ -70,6 +70,7 @@ describe("Test /api/gist", () => {
   it("should get the query options", async () => {
     const req = {
       query: {
+        id: "bbfce31e0217a3689c8d961a356cb10d",
         title_color: "fff",
         icon_color: "fff",
         text_color: "fff",