From 2e619cc8a85157e91a08ccc53511a57038228246 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Sat, 19 Aug 2023 09:35:52 +0300 Subject: [PATCH] feat(gist): handle missing param error (#3101) --- src/fetchers/gist-fetcher.js | 3 ++- tests/fetchGist.test.js | 6 ++++++ tests/gist.test.js | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) 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} 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; 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",