refactor(ibex): collapse payInvoice raw-fetch seam onto the SDK path - #479
Merged
Conversation
payInvoice called the generated SDK through Ibex.authentication.withAuth directly so a failed payment's FetchError — carrying the parsed IBEX error body on `.data` — reached httpErrorHandler intact. The seam existed because ibex-client 3.2.0's ApiError discarded the response body (lnflash/ibex-client#6), which made insufficient-balance 400s unclassifiable through the standard path. As of ibex-client 3.3.0 (#477), ApiError extracts the body itself (httpCode / ibexResponse / ibexMessage) and errorHandler classifies it through the standard path, so payInvoice now uses the same `Ibex.payInvoiceV2(body).then(errorHandler)` shape as every sibling method. httpErrorHandler had no remaining callers after the collapse and is removed along with its dedicated tests; every behavioral pin it carried (insufficient-balance classification with UUID-stripped client message and preserved detail, single-copy detail on unclassified errors, capped message on oversized bodies, status preservation, network-failure and non-Error tolerance) now lives on the errorHandler path in errors.spec.ts, constructed as real ApiErrors — the exact shape the collapsed path produces. pay-invoice.spec.ts mocks ibex-client 3.3.0's wrapper contract and gains a payInvoice-level auth-failure test pinning ErrorLevel.Critical. Fixes #478 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH
bobodread876
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What the seam was
payInvoiceinsrc/services/ibex/client.tsinvoked the generated SDK throughIbex.authentication.withAuth(() => Ibex.ibex.payInvoiceV2(...))with a.catch(httpErrorHandler), instead of the standardIbex.payInvoiceV2(...).then(errorHandler)shape every sibling method uses. The seam existed because ibex-client 3.2.0'sApiErrorwrapper discarded the response body (lnflash/ibex-client#6): the rawFetchError(parsed body on.data) had to reachhttpErrorHandlerintact or insufficient-balance 400s were unclassifiable.Why it's safe to collapse now
ibex-client 3.3.0 (bumped in #477) makes
ApiErrorextract the body itself —httpCode/ibexResponse/ibexMessage— anderrorHandlerclassifies that shape through the standard path. The wrapper's contract (withAuth(...).catch(_ => new ApiError(_)), resolving auth failures asAuthenticationErrorvalues) means every error class the seam handled now arrives aterrorHandlerwith the same information:InsufficientIbexBalance,ErrorLevel.Info, UUID-stripped client message, unstripped vendordetailpreserved for logs/spansIbexError(Warn) carrying the IBEX body detail exactly once (no duplication with ApiError's own embedded copy), capped atMAX_IBEX_MESSAGE_LENGTHfor oversized (e.g. Cloudflare HTML) bodiesIbexErroratErrorLevel.CriticalIbexErrorwithout a statusWhat happened to httpErrorHandler
Removed. After the collapse it had zero production callers (
ibexFetch/ibexPostbuild their ownIbexErrorinline and never routed through it), and a fully-dead defense-in-depth handler rots. Its dedicated describe block is removed with it; every behavioral pin it carried was ported onto theerrorHandlerpath (see below), so no assertion coverage was lost — only the duplicate route to it.Tests
test/flash/unit/services/ibex/errors.spec.ts— the "ibex-client 3.3.0 integration" describe now pins the full collapsed-path behavior with realApiErrorconstruction (the exact shape the wrapper resolves with): JSON and non-JSON insufficient-balance bodies, casing preservation, case-insensitive classification, payment-already-prepared, unclassified detail carried exactly once with status + level, bounded message on oversized bodies, network-level failure without status, non-Error throwable tolerance, status preservation on body-less errors.test/flash/unit/services/ibex/pay-invoice.spec.ts— mock now mirrors ibex-client 3.3.0's wrapper contract (unwrap.data, resolveAuthenticationError, resolve thrown errors asnew ApiError(err)) instead of stubbingwithAuth; adds a payInvoice-level auth-failure test pinningErrorLevel.Critical.yarn test:unit: 181 suites, 1585 passed / 3 skipped.yarn tsc-checkclean; eslint clean on all changed files.Fixes #478
🤖 Generated with Claude Code
https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH