iroha
iroha copied to clipboard
refactor!: refine `/transaction` route response
Context
This PR updates the HTTP response codes returned by Iroha when handling transactions, making them more consistent and expressive for different failure modes. Currently, the API:
- Returns
200 OKwhen a transaction is accepted, with no response body. - Returns
400 Bad Requestfor a wide variety of issues. - Returns
500 Internal Server Errorwhen the queue is full.
Problem
This approach lacks granularity and makes it hard for clients to reliably interpret what went wrong, especially in automated systems. It also does not follow common REST conventions.
Fixes #5391
Solution
This PR introduces the following improvements:
202 Acceptedwhen a transaction is successfully accepted into the pipeline (instead of200).400 Bad Requestfor cases like:- Transaction already in queue
- Transaction already in blockchain
- Transaction expired or has a future timestamp
- Transaction exceeds user limits
- Chain ID mismatch
401 Unauthorizedwhen signature verification fails.403 Forbiddenwhen the transaction is signed by the genesis account.503 Service Unavailablewhen the transaction queue is full.
Migration Guide (optional)
Breaking Change:
- Clients that expect
200 OKupon transaction acceptance will now receive202 Accepted. This should be updated in client-side logic. - Status code-based error handling in clients may need to be updated to handle new codes:
401,403,503.
Review notes (optional)
- The change centralizes HTTP status code logic in
IntoResponse, primarily matching error types. - Review the logic around
AcceptTransactionFailandPushIntoQueuefor accurate status mapping.
Checklist
- [x] I've read
CONTRIBUTING.md. - [] All CI checks pass.
- [x] The response codes are aligned with the issue proposal.
- [x] The status codes follow conventional RESTful standards.
- [ ] (optional) I've written unit tests for the error mapping logic.
- [] All review comments have been resolved.
Yup i saw few tests failing due to status code change, Fixing and adding new tests
I’ve taken the liberty of converting this to a draft for the time being.