fix(minibf): return a JSON error body for a malformed stake address - #1177
fix(minibf): return a JSON error body for a malformed stake address#1177michalrus wants to merge 1 commit into
Conversation
The account endpoints resolved the stake address with
`parse_account_key_param`. For a malformed address, the helper returned
a bare 400 with an empty body. The real Blockfrost API returns a JSON
body with the message "Invalid or malformed stake address format." on
every account endpoint.
A blockfrost-tests run found this mismatch on
`/accounts/{stake_address}/addresses/assets`.
The helper now returns `Error::InvalidStakeAddress`, so all account
endpoints send the correct 400 body.
📝 WalkthroughWalkthroughMinibf adds ChangesStake address error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/minibf/src/routes/accounts.rs (1)
1226-1226: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winVerify the public JSON error contract.
The assertion at Line [1226] confirms the internal error variant. The account route tests confirm only
StatusCode::BAD_REQUEST. Add one HTTP assertion that parses the response body and checksInvalid or malformed stake address format..🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/minibf/src/routes/accounts.rs` at line 1226, Extend the account route test around the InvalidStakeAddress case to parse the HTTP response body and assert it contains the public message “Invalid or malformed stake address format.”, while retaining the existing internal error assertion and BAD_REQUEST status check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/minibf/src/routes/accounts.rs`:
- Line 1226: Extend the account route test around the InvalidStakeAddress case
to parse the HTTP response body and assert it contains the public message
“Invalid or malformed stake address format.”, while retaining the existing
internal error assertion and BAD_REQUEST status check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: eb7d081b-a216-4d98-bd8b-75cfa2a65d6d
📒 Files selected for processing (2)
crates/minibf/src/error.rscrates/minibf/src/routes/accounts.rs
There was a problem hiding this comment.
Pull request overview
This PR aligns MiniBF’s /accounts/* endpoints with Blockfrost behavior by ensuring malformed stake addresses return a structured JSON 400 error body (instead of an empty-body 400), via a dedicated InvalidStakeAddress error variant.
Changes:
- Updated
parse_account_key_paramto returnError::InvalidStakeAddressfor malformed stake-address inputs. - Switched the
/accounts/{stake_address}handler to returnResult<_, Error>so it can propagate the new error consistently. - Added
Error::InvalidStakeAddresswith a Blockfrost-matching JSON body/message inIntoResponse.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/minibf/src/routes/accounts.rs | Propagates a structured InvalidStakeAddress error from stake-address parsing and updates handler/test expectations. |
| crates/minibf/src/error.rs | Introduces InvalidStakeAddress and maps it to the expected JSON 400 response body. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Error::InvalidStakeAddress => ( | ||
| StatusCode::BAD_REQUEST, | ||
| Json(ErrorBody::new( | ||
| 400, | ||
| "Bad Request", |
There was a problem hiding this comment.
I think this is a little over the top. 🤨 No Error variant has a JSON body test. The only error-body test in the crate is on PaginationError::InvalidFromTo, which is a different type.
Resolves #1178.
Follow-up to:
/accounts/<account>/addresses/assets#1067Problem
The account endpoints resolved the stake address with
parse_account_key_param.For a malformed address, the helper returned a bare
http/400with an empty body.The real Blockfrost API returns a JSON body with the message "Invalid or malformed stake address format." on every account endpoint.
A
blockfrost-testsrun found this mismatch on/accounts/{stake_address}/addresses/assets.Solution
The helper now returns
Error::InvalidStakeAddress, so all account endpoints send the correct 400 body.Summary by CodeRabbit
400 Bad Requestresponse with a specific error message.