fix: keep the Key not found prefix so routstr SDK purges dead keys

This commit is contained in:
9qeklajc
2026-09-29 01:42:13 +02:00
parent 5b19a7c663
commit f5e95a502c
4 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ separately as `key_not_found` (also 401) — see
{
"error": {
"type": "invalid_request_error",
"message": "API key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"message": "Key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"code": "key_not_found"
}
}
+1 -1
View File
@@ -129,7 +129,7 @@ by key pruning. This is *not* a formatting problem.
{
"error": {
"type": "invalid_request_error",
"message": "API key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"message": "Key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"code": "key_not_found"
}
}
+6 -1
View File
@@ -298,11 +298,16 @@ async def _validate_bearer_key_locked(
# Falling through to the generic handler below would report it as
# "Invalid API key format", sending callers after a formatting bug
# that does not exist. Report the real cause instead.
#
# Keep the "Key not found." prefix verbatim: @routstr/sdk (<=0.4.6)
# detects a dead key with a case-sensitive `body.includes("Key not
# found")` probe, and uses it to purge the key from its store. The
# refund path in balance.py already relies on the same prefix.
raise HTTPException(
status_code=401,
detail={
"error": {
"message": "API key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"message": "Key not found. Deposit first via /v1/wallet/create to get a key on this node.",
"type": "invalid_request_error",
"code": "key_not_found",
}
+4
View File
@@ -350,6 +350,10 @@ async def test_unknown_sk_key_reports_key_not_found(session: AsyncSession) -> No
assert detail["error"]["type"] == "invalid_request_error"
assert detail["error"]["code"] == "key_not_found"
assert "format" not in detail["error"]["message"].lower()
# @routstr/sdk (<=0.4.6) purges a dead key on a case-sensitive
# `body.includes("Key not found")` probe, so the prefix is part of the
# wire contract, not cosmetic.
assert detail["error"]["message"].startswith("Key not found.")
@pytest.mark.asyncio