mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-08 16:39:42 +02:00
fix(custom-model,toast): surface the real apply error, and make error toasts sticky with a close button
Two related fixes, both needed to actually diagnose 'Session started on the native backend — could not apply the custom endpoint' reports from live testing: 1. runCustomModelEntry()'s apply call went through _apiJson(), which unwraps a success body but SWALLOWS a failure response entirely and returns null — discarding the one thing (error, errorCode) that would tell 'endpoint unreachable' apart from 'not a discovered model', 'remote/Docker session', or a dozen other real causes the apply route already reports distinctly. Switched to _api() so the actual response body is read on failure too, and the toast now includes the real message. 2. showToast() defaulted every toast, error or not, to a 3s auto-dismiss with no way to read it again — exactly what made the above generic message impossible to act on even before the fix above. Error toasts now default to sticky (duration: 0, no auto-dismiss) unless a caller opts into a duration, and every toast — sticky or not — gets an explicit close (x) button, since a sticky toast with no way to dismiss it would just accumulate across repeated failures. Tests: custom-model-run-menu-ui.test.ts's two apply tests updated for the _api() switch (their mocks previously stubbed _apiJson, which the apply call no longer goes through), plus a new test pinning that the real server error string reaches the toast on a failure. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RqZeHrRS6DYcGcGX2p9EwG
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
9a9e542a7d
commit
409a6e65f9
@@ -721,12 +721,20 @@ Object.assign(CodemanApp.prototype, {
|
||||
const sessionId = this.activeSessionId;
|
||||
if (!sessionId || sessionId === before) return;
|
||||
|
||||
const data = await this._apiJson(`/api/sessions/${sessionId}/custom-model`, {
|
||||
// _apiJson() (used everywhere else in this file) unwraps a success body to
|
||||
// its `data`, but on failure it swallows the response entirely and returns
|
||||
// null — exactly the `error` text a caller needs to tell "the endpoint is
|
||||
// unreachable" apart from "the CLI can't be redirected", "not one of the
|
||||
// discovered models", or "this is a Docker/remote session". Go through the
|
||||
// raw response here instead so a failure is diagnosable, not just present.
|
||||
const res = await this._api(`/api/sessions/${sessionId}/custom-model`, {
|
||||
method: 'POST',
|
||||
body: { endpointId, modelId },
|
||||
});
|
||||
if (!data) {
|
||||
this.showToast(`Session started on the native backend — could not apply the custom endpoint`, 'warning');
|
||||
const data = res ? await res.json().catch(() => null) : null;
|
||||
if (!data || data.success === false) {
|
||||
const detail = data?.error ? `: ${data.error}` : res ? ` (HTTP ${res.status})` : ' (request failed)';
|
||||
this.showToast(`Session started on the native backend — could not apply the custom endpoint${detail}`, 'error');
|
||||
return;
|
||||
}
|
||||
this.showToast(`Pointed at ${endpointId} — restarting the session...`, 'info');
|
||||
|
||||
Reference in New Issue
Block a user