diff --git a/src/lib/api/lnbits.ts b/src/lib/api/lnbits.ts index 6782808..700df9a 100644 --- a/src/lib/api/lnbits.ts +++ b/src/lib/api/lnbits.ts @@ -116,12 +116,29 @@ export class LnbitsAPI extends BaseService { if (!response.ok) { const errorText = await response.text() + // Try to surface FastAPI's `{"detail": "..."}` shape; fall back to raw + // body for non-JSON errors. Without this, every backend error renders + // as a generic "API request failed: " and you can't distinguish + // "wrong endpoint" from "expired token" from "validation failure". + let detail: string = errorText + try { + const parsed = JSON.parse(errorText) + if (parsed && typeof parsed.detail === 'string') { + detail = parsed.detail + } else if (parsed && Array.isArray(parsed.detail)) { + // pydantic ValidationError: take the first msg + detail = parsed.detail[0]?.msg ?? errorText + } + } catch { + // body wasn't JSON; keep the raw text in `detail` + } console.error('LNBits API Error:', { + endpoint, status: response.status, statusText: response.statusText, - errorText + detail, }) - throw new Error(`API request failed: ${response.status} ${response.statusText}`) + throw new Error(`LNbits ${endpoint} ${response.status}: ${detail || response.statusText}`) } const data = await response.json() @@ -192,8 +209,12 @@ export class LnbitsAPI extends BaseService { } async updateProfile(data: Partial): Promise { - return this.request('/auth/update', { - method: 'PUT', + // aiolabs/lnbits PR #26 (gap-fill 869f67c3) wired + // _publish_nostr_metadata_event into PATCH /api/v1/auth + // (auth_api.py:546). The legacy PUT /auth/update route does not + // exist on the post-cascade server. + return this.request('/auth', { + method: 'PATCH', body: JSON.stringify(data), }) }