mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 17:27:15 +00:00
fix(browser): stop wrapping application errors with Can't reach message
This commit is contained in:
committed by
Peter Steinberger
parent
47f52cd233
commit
e555bfb1d8
@@ -9,6 +9,15 @@ import {
|
|||||||
} from "./control-service.js";
|
} from "./control-service.js";
|
||||||
import { createBrowserRouteDispatcher } from "./routes/dispatcher.js";
|
import { createBrowserRouteDispatcher } from "./routes/dispatcher.js";
|
||||||
|
|
||||||
|
// Application-level error from the browser control service (service is reachable
|
||||||
|
// but returned an error response). Must NOT be wrapped with "Can't reach ..." messaging.
|
||||||
|
class BrowserServiceError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "BrowserServiceError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type LoopbackBrowserAuthDeps = {
|
type LoopbackBrowserAuthDeps = {
|
||||||
loadConfig: typeof loadConfig;
|
loadConfig: typeof loadConfig;
|
||||||
resolveBrowserControlAuth: typeof resolveBrowserControlAuth;
|
resolveBrowserControlAuth: typeof resolveBrowserControlAuth;
|
||||||
@@ -140,7 +149,7 @@ async function fetchHttpJson<T>(
|
|||||||
const res = await fetch(url, { ...init, signal: ctrl.signal });
|
const res = await fetch(url, { ...init, signal: ctrl.signal });
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const text = await res.text().catch(() => "");
|
const text = await res.text().catch(() => "");
|
||||||
throw new Error(text || `HTTP ${res.status}`);
|
throw new BrowserServiceError(text || `HTTP ${res.status}`);
|
||||||
}
|
}
|
||||||
return (await res.json()) as T;
|
return (await res.json()) as T;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -235,10 +244,13 @@ export async function fetchBrowserJson<T>(
|
|||||||
result.body && typeof result.body === "object" && "error" in result.body
|
result.body && typeof result.body === "object" && "error" in result.body
|
||||||
? String((result.body as { error?: unknown }).error)
|
? String((result.body as { error?: unknown }).error)
|
||||||
: `HTTP ${result.status}`;
|
: `HTTP ${result.status}`;
|
||||||
throw new Error(message);
|
throw new BrowserServiceError(message);
|
||||||
}
|
}
|
||||||
return result.body as T;
|
return result.body as T;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof BrowserServiceError) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
throw enhanceBrowserFetchError(url, err, timeoutMs);
|
throw enhanceBrowserFetchError(url, err, timeoutMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user