Skip to content

Commit

Permalink
hotfix(frontend): Return DEFAULT_SETTINGS if GET /settings is 404 (Al…
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape authored and Kevin Chen committed Feb 4, 2025
1 parent 75de5b6 commit 12788ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
44 changes: 14 additions & 30 deletions frontend/src/hooks/query/use-settings.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
import { useQuery } from "@tanstack/react-query";
import React from "react";
import posthog from "posthog-js";
import { AxiosError } from "axios";
import { DEFAULT_SETTINGS } from "#/services/settings";
import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";

const getSettingsQueryFn = async () => {
try {
const apiSettings = await OpenHands.getSettings();

if (apiSettings !== null) {
return {
LLM_MODEL: apiSettings.llm_model,
LLM_BASE_URL: apiSettings.llm_base_url,
AGENT: apiSettings.agent,
LANGUAGE: apiSettings.language,
CONFIRMATION_MODE: apiSettings.confirmation_mode,
SECURITY_ANALYZER: apiSettings.security_analyzer,
LLM_API_KEY: apiSettings.llm_api_key,
REMOTE_RUNTIME_RESOURCE_FACTOR:
apiSettings.remote_runtime_resource_factor,
GITHUB_TOKEN_IS_SET: apiSettings.github_token_is_set,
ENABLE_DEFAULT_CONDENSER: apiSettings.enable_default_condenser,
};
}

return DEFAULT_SETTINGS;
} catch (error) {
if (error instanceof AxiosError) {
if (error.response?.status === 404) {
return DEFAULT_SETTINGS;
}
}

throw error;
}
const apiSettings = await OpenHands.getSettings();

return {
LLM_MODEL: apiSettings.llm_model,
LLM_BASE_URL: apiSettings.llm_base_url,
AGENT: apiSettings.agent,
LANGUAGE: apiSettings.language,
CONFIRMATION_MODE: apiSettings.confirmation_mode,
SECURITY_ANALYZER: apiSettings.security_analyzer,
LLM_API_KEY: apiSettings.llm_api_key,
REMOTE_RUNTIME_RESOURCE_FACTOR: apiSettings.remote_runtime_resource_factor,
GITHUB_TOKEN_IS_SET: apiSettings.github_token_is_set,
ENABLE_DEFAULT_CONDENSER: apiSettings.enable_default_condenser,
};
};

export const useSettings = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/query-client-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryClientConfig, QueryCache } from "@tanstack/react-query";
import { renderToastIfError } from "./utils/render-toast-if-error";

const QUERY_KEYS_TO_IGNORE = ["authenticated", "hosts"];
const QUERY_KEYS_TO_IGNORE = ["authenticated", "hosts", "settings"];

export const queryClientConfig: QueryClientConfig = {
queryCache: new QueryCache({
Expand Down

0 comments on commit 12788ba

Please sign in to comment.