Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): show a model-listing failure once, not also as a toast

Elian Doranff3e9fd844ff
diff --git a/apps/client/src/services/llm_chat.spec.ts b/apps/client/src/services/llm_chat.spec.ts
index 165c8822ac..aa3da0f53c 100644
--- a/apps/client/src/services/llm_chat.spec.ts
+++ b/apps/client/src/services/llm_chat.spec.ts
@@ -54,8 +54,9 @@ describe("fetchProviderModels", () => {
server.postWithTimeout = vi.fn(async () => ({ models })) as typeof server.postWithTimeout;
const query = { provider: "openai", apiKey: "sk-test", baseURL: "http://localhost:11434/v1" };
await expect(fetchProviderModels(query)).resolves.toBe(models);
- // Long enough for a first Google Antigravity sign-in, which runs inside this request.
- expect(server.postWithTimeout).toHaveBeenCalledWith("llm-chat/provider-models", 6 * 60_000, query);
+ // Long enough for a first Google Antigravity sign-in, which runs inside this request. The
+ // model-selection screen shows a failure inline, so no toast repeats it.
+ expect(server.postWithTimeout).toHaveBeenCalledWith("llm-chat/provider-models", 6 * 60_000, query, undefined, { silentBadRequest: true });
});
it("defaults to an empty array when models is absent", async () => {
diff --git a/apps/client/src/services/llm_chat.ts b/apps/client/src/services/llm_chat.ts
index b7b72155bf..9b6e91f1ec 100644
--- a/apps/client/src/services/llm_chat.ts
+++ b/apps/client/src/services/llm_chat.ts
@@ -22,11 +22,12 @@ const PROVIDER_MODELS_TIMEOUT_MS = 6 * 60_000;
* Fetch the live model list for a provider from its credentials. Used by the
* model-selection screen while adding or editing a provider — the config need
* not be saved yet. A server-side failure (e.g. a bad API key) rejects with a
- * clean message the screen can display.
+ * clean message the screen can display, and shows no toast.
*/
export async function fetchProviderModels(query: ProviderModelsQuery): Promise<LlmModelInfo[]> {
try {
- const response = await server.postWithTimeout<{ models?: LlmModelInfo[] }>("llm-chat/provider-models", PROVIDER_MODELS_TIMEOUT_MS, query);
+ const response = await server.postWithTimeout<{ models?: LlmModelInfo[] }>(
+ "llm-chat/provider-models", PROVIDER_MODELS_TIMEOUT_MS, query, undefined, { silentBadRequest: true });
return response.models ?? [];
} catch (error) {
throw new Error(serverErrorMessage(error));
diff --git a/apps/client/src/services/server.spec.ts b/apps/client/src/services/server.spec.ts
index 1e4e880215..07ab83f053 100644
--- a/apps/client/src/services/server.spec.ts
+++ b/apps/client/src/services/server.spec.ts
@@ -216,6 +216,15 @@ describe("ajax error handling", () => {
expect((window as any).logError).not.toHaveBeenCalled();
});
+ it("stays silent on 400 when silentBadRequest is set, still rejecting with the body", async () => {
+ (window as any).$.ajax = (opts: AjaxOptions) => {
+ opts.error({ status: 400, responseText: JSON.stringify({ message: "CLI not found" }) });
+ };
+ await expect(server.postWithTimeout("url", 1000, {}, undefined, { silentBadRequest: true }))
+ .rejects.toBe(JSON.stringify({ message: "CLI not found" }));
+ expect(toastMock.showError).not.toHaveBeenCalled();
+ });
+
it("reports validation errors (400) and still rejects when reportError throws", async () => {
(window as any).$.ajax = (opts: AjaxOptions) => {
opts.error({ status: 400, responseText: JSON.stringify({ message: "Bad input" }) });
diff --git a/apps/client/src/services/server.ts b/apps/client/src/services/server.ts
index ccd048cc19..619109b6e8 100644
--- a/apps/client/src/services/server.ts
+++ b/apps/client/src/services/server.ts
@@ -74,9 +74,12 @@ async function getWithTimeout<T>(url: string, timeoutMs: number, componentId?: s
return await call<T>("GET", url, componentId, { timeoutMs });
}
-/** The POST counterpart of {@link getWithTimeout}. */
-async function postWithTimeout<T>(url: string, timeoutMs: number, data?: unknown, componentId?: string) {
- return await call<T>("POST", url, componentId, { data, timeoutMs });
+/**
+ * The POST counterpart of {@link getWithTimeout}. `silence` suppresses the error toast for a
+ * caller that shows the failure itself.
+ */
+async function postWithTimeout<T>(url: string, timeoutMs: number, data?: unknown, componentId?: string, silence?: Pick<CallOptions, "silentBadRequest">) {
+ return await call<T>("POST", url, componentId, { data, timeoutMs, ...silence });
}
async function put<T>(url: string, data?: unknown, componentId?: string) {
@@ -167,6 +170,8 @@ interface CallOptions {
data?: unknown;
silentNotFound?: boolean;
silentInternalServerError?: boolean;
+ /** Suppresses the error toast for a 400, for callers that show the server's message themselves. */
+ silentBadRequest?: boolean;
/** Suppresses the generic error toast for a 401, for callers that present the failure themselves
* (e.g. the OneNote import dialog showing an expired connection inline, with the server's reason). */
silentUnauthorized?: boolean;
@@ -283,6 +288,8 @@ function ajax(url: string, method: string, data: unknown, headers: Headers, opts
// report nothing
} else if (opts.silentUnauthorized && jqXhr.status === 401) {
// report nothing
+ } else if (opts.silentBadRequest && jqXhr.status === 400) {
+ // report nothing
} else {
try {
await reportError(method, url, jqXhr.status, jqXhr.responseText);
@@ -378,7 +385,8 @@ async function localAjax(
const silenced = (opts.silentNotFound && resp.status === 404)
|| (opts.silentInternalServerError && resp.status === 500)
- || (opts.silentUnauthorized && resp.status === 401);
+ || (opts.silentUnauthorized && resp.status === 401)
+ || (opts.silentBadRequest && resp.status === 400);
if (!silenced) {
try {