Compare commits
2 commits
531de18ad7
...
ba916a4c37
| Author | SHA1 | Date | |
|---|---|---|---|
| ba916a4c37 | |||
| 261eded316 |
1 changed files with 25 additions and 4 deletions
|
|
@ -112,12 +112,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: <status>" 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()
|
||||
|
|
@ -186,8 +203,12 @@ export class LnbitsAPI extends BaseService {
|
|||
}
|
||||
|
||||
async updateProfile(data: Partial<User>): Promise<User> {
|
||||
return this.request<User>('/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<User>('/auth', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue