From 73796e8197cd9e344ce6327e6956aa17c815454e Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 15 Jan 2025 00:36:57 +0530 Subject: [PATCH] silence only if 404 --- src/Utils/request/query.ts | 7 ++++++- src/Utils/request/types.ts | 2 +- src/hooks/useQuestionnaireOptions.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Utils/request/query.ts b/src/Utils/request/query.ts index 34fc3ce89ac..68a4e1b0bba 100644 --- a/src/Utils/request/query.ts +++ b/src/Utils/request/query.ts @@ -32,10 +32,15 @@ export async function callApi>( const data = await getResponseBody(res); if (!res.ok) { + const isSilent = + typeof options?.silent === "function" + ? options.silent(res) + : (options?.silent ?? false); + throw new HTTPError({ message: "Request Failed", status: res.status, - silent: options?.silent ?? false, + silent: isSilent, cause: data as unknown as Record, }); } diff --git a/src/Utils/request/types.ts b/src/Utils/request/types.ts index 113fe2a5575..591b4404968 100644 --- a/src/Utils/request/types.ts +++ b/src/Utils/request/types.ts @@ -49,7 +49,7 @@ export interface ApiCallOptions> { pathParams?: PathParams; queryParams?: QueryParams; body?: Route["TBody"]; - silent?: boolean; + silent?: boolean | ((response: Response) => boolean); signal?: AbortSignal; headers?: HeadersInit; } diff --git a/src/hooks/useQuestionnaireOptions.ts b/src/hooks/useQuestionnaireOptions.ts index 3403a260311..73a0724865e 100644 --- a/src/hooks/useQuestionnaireOptions.ts +++ b/src/hooks/useQuestionnaireOptions.ts @@ -22,7 +22,7 @@ export default function useQuestionnaireOptions(slug: string) { queryParams: { tag_slug: slug, }, - silent: true, + silent: (res) => res.status === 404, }), });