Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Route apiSystem's downloadBackupSnapshot through throwApiError too
Bryandero989031c93602e1
diff --git a/client/src/services/apiCore.test.js b/client/src/services/apiCore.test.jsindex d90b50075a..746c360f9d 100644--- a/client/src/services/apiCore.test.js+++ b/client/src/services/apiCore.test.js@@ -93,4 +93,13 @@ describe('request() error path (now delegating to throwApiError)', () => {await expect(request('/x', { silent: true })).rejects.toMatchObject({ status: 500 });expect(toast.error).not.toHaveBeenCalled();});++ it('suppresses the PLATFORM_UNAVAILABLE warning toast too when { silent: true } is passed', async () => {+ global.fetch.mockResolvedValue(+ makeResponse({ status: 503, json: { error: 'offline', code: 'PLATFORM_UNAVAILABLE' } }),+ );+ await expect(request('/x', { silent: true })).rejects.toMatchObject({ code: 'PLATFORM_UNAVAILABLE' });+ expect(toast).not.toHaveBeenCalled();+ expect(toast.error).not.toHaveBeenCalled();+ });});diff --git a/client/src/services/apiMedia.test.js b/client/src/services/apiMedia.test.jsindex 069cc25f89..14b9755a81 100644--- a/client/src/services/apiMedia.test.js+++ b/client/src/services/apiMedia.test.js@@ -11,7 +11,12 @@ vi.mock('./apiCore.js', () => {// these tests instead of a mock that silently drops the side effect.const maybeRedirectToLogin = vi.fn();const throwApiError = vi.fn(async (response) => {- const error = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));+ // Mirrors apiCore's own null-safety: a valid JSON body that isn't an+ // object (e.g. a bare `null`) has no `.error`/`.code`/`.context` to read,+ // so it falls back to the same HTTP-status shape as non-JSON bodies.+ const parsedError = await response.json().catch(() => null);+ const error =+ parsedError && typeof parsedError === 'object' ? parsedError : { error: `HTTP ${response.status}` };maybeRedirectToLogin(response, error);const err = new Error(error.error || `HTTP ${response.status}`);err.code = error?.code;@@ -87,6 +92,14 @@ describe('cleanImage', () => {await expect(cleanImage(fakeFile, { diffusion: 'gpu' })).rejects.toMatchObject({ code: 'REGEN_BACKEND_UNAVAILABLE' });});+ it('forwards structured error.context through the direct-fetch wrapper', async () => {+ const context = { jobId: 'j1', retryable: false };+ global.fetch.mockResolvedValue(+ makeResponse({ status: 409, ok: false, json: { error: 'busy', code: 'ERR_BUSY', context } }),+ );+ await expect(cleanImage(fakeFile, { diffusion: 'gpu' })).rejects.toMatchObject({ context });+ });+it('honors session expiry the same way request() does (401 AUTH_REQUIRED)', async () => {const response = makeResponse({ status: 401, ok: false, json: { error: 'auth required', code: 'AUTH_REQUIRED' } });global.fetch.mockResolvedValue(response);diff --git a/client/src/services/apiSystem.download.test.js b/client/src/services/apiSystem.download.test.jsindex d981d30127..52bb7a7e6f 100644--- a/client/src/services/apiSystem.download.test.js+++ b/client/src/services/apiSystem.download.test.js@@ -55,6 +55,17 @@ describe('downloadBackupSnapshot', () => {expect(URL.createObjectURL).not.toHaveBeenCalled();});+ it('forwards structured error.context from a failed download response', async () => {+ const context = { snapshotId: 'missing', retryable: false };+ fetch.mockResolvedValue({+ ok: false,+ status: 409,+ json: vi.fn().mockResolvedValue({ error: 'snapshot locked', code: 'ERR_SNAPSHOT_LOCKED', context }),+ });++ await expect(downloadBackupSnapshot('missing')).rejects.toMatchObject({ context });+ });+it('streams large responses to a file picker when available', async () => {const pipeTo = vi.fn().mockResolvedValue(undefined);const writable = {};diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.jsindex f3043849c7..d15e2800b0 100644--- a/client/src/services/apiSystem.js+++ b/client/src/services/apiSystem.js@@ -1,4 +1,4 @@-import { request, API_BASE, maybeRedirectToLogin } from './apiCore.js';+import { request, API_BASE, throwApiError } from './apiCore.js';import { downloadBlob } from '../lib/downloadBlob.js';// Alerts@@ -195,12 +195,7 @@ export async function downloadBackupSnapshot(snapshotId) {// Close the handle we opened before we knew the request would fail, so the// picker doesn't leave a 0-byte file behind.await writable?.abort?.().catch(() => {});- const error = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));- maybeRedirectToLogin(response, error);- const err = new Error(error.error || `HTTP ${response.status}`);- err.code = error.code;- err.status = response.status;- throw err;+ await throwApiError(response);}if (writable && response.body?.pipeTo) {