From 6fa98ca5ae75ae8876a82aebab35f214419e42b5 Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Sun, 9 Aug 2026 14:21:00 +0200 Subject: [PATCH] use specific error message/code --- routstr/balance.py | 8 +++++++- tests/unit/test_balance.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/routstr/balance.py b/routstr/balance.py index b2aaaaeb..22365f39 100644 --- a/routstr/balance.py +++ b/routstr/balance.py @@ -439,7 +439,13 @@ async def refund_wallet_endpoint( if key is None: raise HTTPException( status_code=401, - detail="Key not found. Deposit first via /v1/wallet/create before requesting a refund.", + detail={ + "error": { + "message": "Key not found. Deposit first via /v1/wallet/create before requesting a refund.", + "type": "invalid_request_error", + "code": "key_not_found", + } + }, ) if key.total_balance <= 0: diff --git a/tests/unit/test_balance.py b/tests/unit/test_balance.py index 1bf94c94..93ab4aea 100644 --- a/tests/unit/test_balance.py +++ b/tests/unit/test_balance.py @@ -548,6 +548,13 @@ async def test_refund_fresh_cashu_bearer_returns_401() -> None: ) assert exc_info.value.status_code == 401 + assert exc_info.value.detail == { + "error": { + "message": "Key not found. Deposit first via /v1/wallet/create before requesting a refund.", + "type": "invalid_request_error", + "code": "key_not_found", + } + } session.get.assert_awaited_once() # No add/commit → no key was persisted session.add.assert_not_called()