mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-29 23:27:45 +00:00
EHBP encrypts response bodies, error bodies included. On a non-200 the proxy decoded the ciphertext as UTF-8 and wrapped it in its own JSON error envelope, so callers saw mojibake instead of the enclave's actual reason (a real-world 404 caused by an upstream model id surfaced only as `EHBP upstream tinfoil returned 404 ... <binary garbage>`), and the provider status was lost behind the 424 mapping. When the enclave response carries `Ehbp-Response-Nonce`, reconstruct the reply verbatim -- status, nonce header and ciphertext body -- and raise `EhbpEncryptedUpstreamError`. Failover, cooldown accounting and reservation release are unchanged; once the provider chain is exhausted, `proxy.py` returns the enclave reply instead of a proxy envelope, and the EHBP client decrypts the provider's real error. Already-plaintext non-200s (router/gateway rejections without a nonce) keep the existing structured-error handling. X-Cashu requests refund the token and relay the ciphertext together with the `X-Cashu` refund header. Ciphertext is also kept out of the proxy's error logs and messages; the log line records the byte count instead.