The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(cloud): D2 - "Failed to fetch" ist keine Erklaerung mehr
purple730e6cf57b7d
diff --git a/src/api/cloud/__tests__/cloud-client.test.ts b/src/api/cloud/__tests__/cloud-client.test.tsindex aabe66d5..7d1718d5 100644--- a/src/api/cloud/__tests__/cloud-client.test.ts+++ b/src/api/cloud/__tests__/cloud-client.test.ts@@ -197,6 +197,34 @@ describe('cloudFetch', () => {await expect(cloudFetch('/api/me', { signal: ac.signal })).rejects.toThrow()})+ it('D2: a raw network failure becomes an actionable message, not the browser\'s own text', async () => {+ // The window between a Desktop release and the matching Web deploy: the+ // new app calls a route the still-old server does not have, an unmatched+ // Next.js API route commonly answers without CORS headers, and the+ // browser rejects the bare fetch() with a generic TypeError instead of+ // ever handing back a status. Every caller in this app puts err.message+ // straight into its own error banner, so this raw string used to be the+ // ENTIRE explanation a customer ever saw.+ fetchMock.mockRejectedValue(new TypeError('Failed to fetch'))+ const err = await cloudFetch('/api/account/content-policy').catch((e: unknown) => e)+ expect(err).toBeInstanceOf(CloudJobError)+ expect((err as CloudJobError).message).not.toBe('Failed to fetch')+ expect((err as CloudJobError).message).toMatch(/could not reach/i)+ })++ it('D2: a deliberate cancel is NOT relabelled — it must stay tellable from a real failure', async () => {+ // Regression guard for the fix above: it must only reword a genuine+ // network failure, never a caller-initiated Stop/teardown, which every+ // existing caller already distinguishes by checking `instanceof+ // CloudJobError`.+ const ac = new AbortController()+ fetchMock.mockImplementation(hangingFetch())+ const settled = cloudFetch('/api/me', { signal: ac.signal }).catch((e: unknown) => e)+ ac.abort()+ const err = await settled+ expect(err).not.toBeInstanceOf(CloudJobError)+ })+it('preserves method, body and extra headers', async () => {fetchMock.mockResolvedValue(jsonRes({}))await cloudFetch('/api/jobs', {diff --git a/src/api/cloud/client.ts b/src/api/cloud/client.tsindex 29631f86..b6ded899 100644--- a/src/api/cloud/client.ts+++ b/src/api/cloud/client.ts@@ -157,7 +157,14 @@ export async function cloudFetch(path: string, init: CloudFetchInit = {}): Promi// would merge them, but it is newer than the WKWebView LU runs inside on// older macOS, so the relay is wired by hand.const ac = new AbortController()- const relay = () => ac.abort(signal?.reason)+ // D2 (3.0.1): set the moment the CALLER's own signal is why `ac` aborted,+ // same idea as `timedOut` below but for cancellation instead of a deadline.+ // Needed to tell "the user/run cancelled this" apart from "the network+ // genuinely failed" in the catch — both end up as a plain, non-CloudJobError+ // rejection from `fetch`/`untilAborted`, and only the second one should be+ // reworded.+ let callerAborted = false+ const relay = () => { callerAborted = true; ac.abort(signal?.reason) }if (signal) {if (signal.aborted) relay()else signal.addEventListener('abort', relay, { once: true })@@ -181,6 +188,29 @@ export async function cloudFetch(path: string, init: CloudFetchInit = {}): Promiif (timedOut && !(err instanceof CloudJobError)) {throw new CloudJobError('the cloud did not answer in time', 408)}+ // D2 (3.0.1): the window between a Desktop release and the matching Web+ // deploy. The new Desktop build calls a route the still-old server does+ // not have yet; an unmatched Next.js API route commonly answers without+ // the app's CORS headers, so the browser never lets the fetch resolve to+ // a status code at all — it rejects the plain `fetch()` call itself with+ // `TypeError: Failed to fetch`. Every caller in this app reads `err instanceof+ // Error ? err.message : ...` straight into its own error banner+ // (ContentPolicySettings.tsx and others), so that raw engine string was+ // the ENTIRE explanation a customer ever saw — no status, no next step.+ // Excluded on purpose: `err instanceof CloudJobError` is already a real+ // server answer (401 above, or one jsonOrError raised before it threw)+ // and keeps its own accurate message; `callerAborted` is a deliberate+ // cancel (Stop, a run tearing down), not a failure, and every existing+ // caller already relies on a cancel staying a plain, non-CloudJobError+ // rejection to tell the two apart. Only a bare, un-typed rejection that+ // is NEITHER of those — a genuine network failure — gets reworded into+ // something a customer can act on.+ if (!callerAborted && !(err instanceof CloudJobError)) {+ throw new CloudJobError(+ 'Could not reach the LU Cloud server. This can happen right after an app update while the server catches up — try again in a moment, or check for a newer version.',+ 0,+ )+ }throw err} finally {// The deadline covers what this function owns: the token (refresh