fix: return structured JSON for malformed request bodies#4441
fix: return structured JSON for malformed request bodies#4441dymchenkko wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Code Review
This pull request introduces a custom Json extractor in crates/orderbook/src/api/extract.rs that wraps Axum's native extractor. When request deserialization fails, it returns a structured JSON error response containing errorType and description instead of plain text. The API endpoints in cancel_order.rs, debug_simulation.rs, post_order.rs, post_quote.rs, and put_app_data.rs have been updated to use this new extractor. Additionally, the OpenAPI specification (openapi.yml) has been updated to document the Error schema for 422 responses. No critical issues were found, and there is no feedback to provide.
|
I have read the CLA Document and I hereby sign the CLA |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
squadgazzz
left a comment
There was a problem hiding this comment.
This is a breaking change for the public API. If any of the clients are parsing errors (which is most likely the case, including our front-end), this change would lead to errors on their end.
|
@dymchenkko , thank you for your contribution! Please fix the PR description formatting. AI tends to generate in the wrong way. |
|
@squadgazzz Hey, thanks for the review! I want to make sure I understand the concern correctly. Before this change, when a request had malformed JSON, Axum returned a plain-text error instead of JSON. Every other error in these endpoints already returns {errorType, description} JSON, that's actually why #4439 and #4440 were filed as bugs. Could you point to a specific client that depends on the plain-text format? That would help me understand what exactly would break. |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
That's the issue, we don't know and there's no way of doing so as the API is open to everyone. |
JSON-body endpoints returned axum's plain-text rejection when a request
body failed to deserialize. Add a Json extractor that renders these
errors in the API's { errorType, description } format and apply it to
all JSON-body endpoints.
Closes cowprotocol#4439
Closes cowprotocol#4440
e07acf1 to
bf249b4
Compare
|
Thanks, no rush. Happy to wait! Let me know if there's anything else I can adjust in the meantime. |
JSON-body endpoints return Axum's plain-text rejection when a request body fails to deserialize. Every other error in this API returns structured {errorType, description} JSON, so clients that parse all responses as JSON break on these cases (#4439, #4440).
Added a thin Json extractor wrapping axum::Json that, on rejection, returns error("InvalidJson", …) with the original status code (422 for bad fields, 400 for invalid syntax). Applied to all JSON-body endpoints: post_order, post_quote, cancel_order, put_app_data, debug_simulation. Also added a generic Error schema to OpenAPI referenced from the affected 422 responses.
To test: cargo nextest run -p orderbook --lib api::extract.
Fixes #4439, fixes #4440.