From 3abc0283956cd063aa547811bb18538cdfa78cab Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Wed, 6 May 2026 18:32:46 +0800 Subject: [PATCH] fix: surface cocod "Not enough proofs" as InsufficientBalanceError When cocod cannot assemble enough proofs to send (e.g. due to denomination fragmentation or stale proof state), it returns "Send failed: Not enough proofs to send". This was propagating as a generic Error, causing the HTTP handler to return 500 instead of the structured 402 insufficient_balance response. Map that cocod error to InsufficientBalanceError in walletAdapter.sendToken so the existing handler path returns the correct 402. Co-Authored-By: Claude Sonnet 4 --- src/daemon/wallet/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/daemon/wallet/index.ts b/src/daemon/wallet/index.ts index c021122..6a64d0a 100644 --- a/src/daemon/wallet/index.ts +++ b/src/daemon/wallet/index.ts @@ -1,4 +1,5 @@ import { getDecodedToken } from "@cashu/cashu-ts"; +import { InsufficientBalanceError } from "@routstr/sdk"; import { logger } from "../../utils/logger"; import { createCocodClient, type CocodClient } from "./cocod-client"; @@ -79,6 +80,10 @@ export async function createWalletAdapter( continue; } + if (errorMessage.includes("Not enough proofs")) { + throw new InsufficientBalanceError(amount, 0); + } + logger.error("Error in walletAdapter sendToken:", error); throw error; }