fix(api): return the generic AppError envelope for extractor errors #479
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-481-extractor-error-handlers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
New
bunyip-api/src/extractors.rsgives the Json / Path / Query / Form extractor configs a genericerror_handler, wired intoApp::new(). A malformed request body or a bad path/query/form parameter now returns the standardAppErrorenvelope ({ success:false, error:{ code, message }, meta:{ request_id } }) with a generic message, instead of actix's default raw parse text. The real parse error is logged viatracing::warn!(extractor, error).The request body was malformed or invalid.Invalid request.json_config()keeps the existing 32 KB limit.Why (BUNYIP-481)
Only
JsonConfigwas registered (size limit, no handler) and Path/Query/Form used actix defaults, so the 149 extractor sites could echo framework parse detail (field names,... at line 1 column 20) to direct API callers, bypassing theAppErrorenvelope every other error uses. Same invariant as BUNYIP-477; this is the direct-API-caller counterpart (the browser BFF was already insulated - bunyip-web reads onlyerror.message, which is absent from actix's default body).Coverage
web::Jsonjson_config()(32 KB limit + handler)web::Pathpath_config()web::Queryquery_config()web::Formform_config()Test
malformed_json_returns_generic_envelope_no_parse_detail: a malformed JSON body returns status 400 witherror.code == BAD_REQUEST, the generic message, a stringmeta.request_id, and noexpected/deserializeparse tells.just check-containergreen (fmt + clippy + full workspace, bunyip-api 111 tests).#BUNYIP-481
Add bunyip-api/src/extractors.rs with generic error_handlers for the Json / Path / Query / Form extractor configs and wire all four into App::new(). A malformed request body or a bad path / query / form parameter now returns the standard AppError envelope with a generic message ("The request body was malformed or invalid." / "Invalid request.") and a request_id, instead of actix's default raw parse text (field names, parse positions). The real parse error is logged via tracing::warn!(extractor, error) so diagnosis is unaffected. Before this, only JsonConfig was registered (size limit, no error handler) and Path / Query / Form used actix defaults, so the 149 extractor sites could echo framework parse detail to direct API callers, bypassing the envelope every other error uses. The browser BFF was already insulated (bunyip-web reads only error.message, absent from actix's default body); this covers direct API and OAuth clients. Sibling to the browser-facing fix in BUNYIP-477. Test: a malformed JSON body returns status 400 with the generic envelope (code BAD_REQUEST, generic message, request_id) and none of actix's parse tells. #BUNYIP-481