Parse structured JSON errors from gateway API responses#126
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughRemoved the unused Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
49ef5d0 to
f93f610
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@binaries/statespace-cli/src/gateway/client.rs`:
- Around line 380-402: Add unit tests for extract_error_message and
map_api_error: create tests that assert extract_error_message parses nested JSON
with {"error": {"message": "..."}}, parses flat {"message": "..."}, returns raw
text when body is non-JSON and that raw result is truncated to 512 chars, and
that map_api_error maps 401 to GatewayError::Unauthorized, 404 to
GatewayError::NotFound(message) preserving the message, and other statuses to
GatewayError::Api { status, message }. Use the function names
extract_error_message and map_api_error to locate code and craft minimal focused
tests for each branch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ea698b90-3ecd-4fb8-b027-0094d732280a
📒 Files selected for processing (2)
binaries/statespace-cli/src/error.rsbinaries/statespace-cli/src/gateway/client.rs
💤 Files with no reviewable changes (1)
- binaries/statespace-cli/src/error.rs
f93f610 to
9f9fa9c
Compare
9f9fa9c to
5e6374d
Compare
Problem
The gateway now returns structured error JSON instead of bare status codes:
{"error": {"code": "CONFLICT", "message": "Application name already taken: foo"}}The CLI wasn't parsing this — users saw empty or unhelpful messages:
After
Summary by CodeRabbit