Skip to content

Commit

Permalink
Add silent for useQuery in useQuestionnaireOptions (#9973)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobjeevan authored Jan 14, 2025
1 parent 364870b commit b36babf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Utils/request/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ export async function callApi<Route extends ApiRoute<unknown, unknown>>(
const data = await getResponseBody<Route["TRes"]>(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<string, unknown>,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ApiCallOptions<Route extends ApiRoute<unknown, unknown>> {
pathParams?: PathParams<Route["path"]>;
queryParams?: QueryParams;
body?: Route["TBody"];
silent?: boolean;
silent?: boolean | ((response: Response) => boolean);
signal?: AbortSignal;
headers?: HeadersInit;
}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useQuestionnaireOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function useQuestionnaireOptions(slug: string) {
queryParams: {
tag_slug: slug,
},
silent: (res) => res.status === 404,
}),
});

Expand Down

0 comments on commit b36babf

Please sign in to comment.