feat(gist): handle missing param error (#3101)
This commit is contained in:
1 parent
ea79314a85
commit
2e619cc8a8
3 files changed
+9
-1
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import { request } from "../common/utils.js";
|
import { request, MissingParamError } from "../common/utils.js";
|
||||||
import { retryer } from "../common/retryer.js";
|
import { retryer } from "../common/retryer.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +57,7 @@ const fetcher = async (variables, token) => {
|
|||||||
* @returns {Promise<GistData>} Gist data.
|
* @returns {Promise<GistData>} Gist data.
|
||||||
*/
|
*/
|
||||||
const fetchGist = async (id) => {
|
const fetchGist = async (id) => {
|
||||||
|
if (!id) throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
|
||||||
const res = await retryer(fetcher, { gistName: id });
|
const res = await retryer(fetcher, { gistName: id });
|
||||||
if (res.data.errors) throw new Error(res.data.errors[0].message);
|
if (res.data.errors) throw new Error(res.data.errors[0].message);
|
||||||
const data = res.data.data.viewer.gist;
|
const data = res.data.data.viewer.gist;
|
||||||
|
|||||||
@@ -69,4 +69,10 @@ describe("Test fetchGist", () => {
|
|||||||
"Some test GraphQL error",
|
"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',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -70,6 +70,7 @@ describe("Test /api/gist", () => {
|
|||||||
it("should get the query options", async () => {
|
it("should get the query options", async () => {
|
||||||
const req = {
|
const req = {
|
||||||
query: {
|
query: {
|
||||||
|
id: "bbfce31e0217a3689c8d961a356cb10d",
|
||||||
title_color: "fff",
|
title_color: "fff",
|
||||||
icon_color: "fff",
|
icon_color: "fff",
|
||||||
text_color: "fff",
|
text_color: "fff",
|
||||||
|
|||||||
Reference in new issue
Block a user