How to handle exception that is generated in rack middleware before it reach rails app?

I know that we can use config.exception_app to set up custom exception
handling and also use rescue_from. However, I have an issue that there
malformed request (testing generated request) that caused Rails Rack
middleware to throw an exception when Rack’s parse_query method. Here
the detail of the

The issue is that it failed in rails Rack::MethodOverride with is
before ActionDispatch::ShowExceptions middleware and way before it even
to the rails app.

So how do we handle the exception gracefully without showing the stack

Thanks for your help.