Are we talking about one-off debugging during development or debugging in the sense that you want to log the body of faulty requests in production? If you want to accept a random JSON value in the body, you can use Json<serde_json::Value> as your extractor.
So... more like the second case then? I.e. you want to use this debugging behaviour in production, but still would like to extract Json<Changes> in your endpoint, no? The client might not send a Changes object, in which case you want to see the body that the client has sent?
In most of the time, things go smoothly. Using Json<Change> is alright. But it may happen like once a year if the client got updated and changed the behavior. I have to follow that.
So instead of when it happens, "let's find out the client and see what it sends". I'd like the failed requests to be recorded with enough information so I can update my side ASAP.
I am not planning to take random inputs. In that case, I surely would just use the raw input in request handler.
I was trying that. But the two parameters of error_handler, err does not (seem to me) contain the JSON string itself. And I need some async functions to get the request body from req, which does not work in error_handler.
Using the Json extractor over Bytes still has benefits like header rejection.
I see two ways to implement this.
Extract body: Json<serde_json::Value> and parse it with serde_json::from_value::<Changes>(body) in your endpoint, allowing you to handle parsing errors (but not general request errors, like wrong content-type) however you like. This would be the easier solution.
A bit more elegant, or rather less visible in your endpoint code, would be to handle this in a middleware. Extracting the body from a request or a response in a middleware is not very convenient though. You'd have to tap into the Payload stream, which is comparatively low-level and you'd have to write some code yourself, which actix-web cleverly hides behind the extractor facade.