MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / createAgentServerQueryClient

Function createAgentServerQueryClient

src/query-client-config.ts:31–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29const shownErrors = new Set<string>();
30
31export const createAgentServerQueryClient = () => {
32 const client = new QueryClient({
33 queryCache: new QueryCache({
34 onSuccess: (_data, query) => {
35 const backendId =
36 query.meta?.backendId ?? query.options.meta?.backendId;
37 if (typeof backendId === "string") {
38 recordBackendSuccess(backendId);
39 }
40 },
41 onError: (error, query) => {
42 const isAuthQuery =
43 query.queryKey[0] === "user" && query.queryKey[1] === "authenticated";
44 if (!isAuthQuery) {
45 handle401Error(error, client);
46 }
47
48 const disableToast =
49 query.meta?.disableToast ?? query.options.meta?.disableToast;
50
51 if (!disableToast && !isActiveCloudBackendAuthError(error)) {
52 const errorMessage = retrieveAxiosErrorMessage(error);
53
54 if (!shownErrors.has(errorMessage || "")) {
55 displayErrorToast(errorMessage || i18n.t(I18nKey.ERROR$GENERIC));
56 shownErrors.add(errorMessage || "");
57
58 setTimeout(() => {
59 shownErrors.delete(errorMessage || "");
60 }, 3000);
61 }
62 }
63 },
64 }),
65 mutationCache: new MutationCache({
66 onError: (error, _, __, mutation) => {
67 handle401Error(error, client);
68
69 const disableToast =
70 mutation?.meta?.disableToast ?? mutation?.options.meta?.disableToast;
71
72 if (!disableToast && !isActiveCloudBackendAuthError(error)) {
73 const message = retrieveAxiosErrorMessage(error);
74 displayErrorToast(message || i18n.t(I18nKey.ERROR$GENERIC));
75 }
76 },
77 }),
78 });
79
80 return client;
81};
82
83let defaultQueryClient: QueryClient | null = null;
84let activeQueryClient: QueryClient | null = null;

Callers 2

getDefaultQueryClientFunction · 0.85

Calls 5

recordBackendSuccessFunction · 0.90
displayErrorToastFunction · 0.90
handle401ErrorFunction · 0.85

Tested by

no test coverage detected