Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): only treat SyntaxError as an absent probe endpoint

raman325fec45411e6c8
diff --git a/apps/server/src/services/llm/providers/local.spec.ts b/apps/server/src/services/llm/providers/local.spec.ts
index ae4f8d70e7..9594e55f6d 100644
--- a/apps/server/src/services/llm/providers/local.spec.ts
+++ b/apps/server/src/services/llm/providers/local.spec.ts
@@ -306,6 +306,23 @@ describe("LocalProvider", () => {
expect(models.map(m => m.id)).toEqual(["m1"]);
});
+ it("surfaces a body-read failure instead of treating it as an absent endpoint", async () => {
+ // A timeout or connection loss while the body streams rejects
+ // json() with a non-SyntaxError; that is a transport problem to
+ // report, not a reason to skip to the next probe.
+ fetchMock.mockImplementation(routes({
+ "/v1/models": {
+ ok: true,
+ status: 200,
+ json: async () => {
+ throw new DOMException("The operation was aborted.", "AbortError");
+ }
+ } as unknown as Response
+ }));
+ await expect(new LocalProvider("openai-compatible", "", "http://box:8080").listModels())
+ .rejects.toThrow("aborted");
+ });
+
it("treats a foreign native payload as 'not that runtime' for the generic card", async () => {
// Something answers /api/tags with unrelated JSON; the generic card
// keeps probing rather than failing on a guess it made itself.
diff --git a/apps/server/src/services/llm/providers/local.ts b/apps/server/src/services/llm/providers/local.ts
index a4544b2136..06e71750ef 100644
--- a/apps/server/src/services/llm/providers/local.ts
+++ b/apps/server/src/services/llm/providers/local.ts
@@ -212,11 +212,16 @@ export class LocalProvider extends BaseProvider {
}
try {
return await response.json();
- } catch {
+ } catch (error) {
// An auth proxy or captive portal can answer a probe with a 200 HTML
// login page (after a redirect fetch follows transparently). A body
- // that isn't JSON means the endpoint isn't served here.
- return undefined;
+ // that isn't JSON means the endpoint isn't served here. Anything
+ // other than a parse failure (timeout or connection loss while the
+ // body streams) is a real transport problem and must surface.
+ if (error instanceof SyntaxError) {
+ return undefined;
+ }
+ throw error;
}
}