mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-07 15:52:52 +03:00
fix(cliproxyapi): address PR #915 review — executor flexibility, fallback error logging
- Export resolveCliproxyapiBaseUrl, accept optional baseUrl in constructor - Log detailed error messages when CLIProxyAPI fallback also fails - Preserve and re-throw fallback errors instead of silently returning
This commit is contained in:
@@ -10,16 +10,19 @@ function resolveCliproxyapiBaseUrl(): string {
|
||||
return `http://${host}:${port}`;
|
||||
}
|
||||
|
||||
export { resolveCliproxyapiBaseUrl };
|
||||
|
||||
export class CliproxyapiExecutor extends BaseExecutor {
|
||||
private readonly upstreamBaseUrl: string;
|
||||
|
||||
constructor() {
|
||||
constructor(baseUrl?: string) {
|
||||
const effectiveBase = baseUrl ?? resolveCliproxyapiBaseUrl();
|
||||
super("cliproxyapi", {
|
||||
id: "cliproxyapi",
|
||||
baseUrl: resolveCliproxyapiBaseUrl() + "/v1/chat/completions",
|
||||
baseUrl: effectiveBase + "/v1/chat/completions",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
this.upstreamBaseUrl = resolveCliproxyapiBaseUrl();
|
||||
this.upstreamBaseUrl = effectiveBase;
|
||||
}
|
||||
|
||||
buildUrl(_model: string, _stream: boolean, _urlIndex = 0): string {
|
||||
|
||||
@@ -1066,12 +1066,25 @@ export async function handleChatCore({
|
||||
"UPSTREAM_PROXY",
|
||||
`${prov} native failed (${result.response.status}), retrying via CLIProxyAPI`
|
||||
);
|
||||
return proxyExec.execute(input);
|
||||
try {
|
||||
return await proxyExec.execute(input);
|
||||
} catch (proxyErr) {
|
||||
const proxyMsg = proxyErr instanceof Error ? proxyErr.message : String(proxyErr);
|
||||
log?.error?.("UPSTREAM_PROXY", `${prov} CLIProxyAPI fallback also failed: ${proxyMsg}`);
|
||||
throw proxyErr;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
log?.info?.("UPSTREAM_PROXY", `${prov} native error, retrying via CLIProxyAPI`);
|
||||
return proxyExec.execute(input);
|
||||
const errMsg = err instanceof Error ? err.message : String(err);
|
||||
log?.info?.("UPSTREAM_PROXY", `${prov} native error (${errMsg}), retrying via CLIProxyAPI`);
|
||||
try {
|
||||
return await proxyExec.execute(input);
|
||||
} catch (proxyErr) {
|
||||
const proxyMsg = proxyErr instanceof Error ? proxyErr.message : String(proxyErr);
|
||||
log?.error?.("UPSTREAM_PROXY", `${prov} CLIProxyAPI fallback also failed: ${proxyMsg}`);
|
||||
throw proxyErr;
|
||||
}
|
||||
}
|
||||
};
|
||||
return wrapper;
|
||||
|
||||
Reference in New Issue
Block a user