salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
2.92k stars 172 forks source link

Enhance Error Handling in Compression Middleware to Properly Propagate Error(StatusError) in ResBody #825

Closed fankaiLiu closed 5 days ago

fankaiLiu commented 6 days ago

Is your feature request related to a problem? Please describe. I'm encountering an issue where the Error(StatusError) in ResBody is being ignored when using compression middleware. Specifically, when the compression middleware is configured with Service::new(router).hoop(Compression::new().enable_gzip(CompressionLevel::Default)), it fails to handle errors as expected, which is quite frustrating. This makes it difficult to manage and log errors effectively, as they are not being propagated or handled after compression is applied.

Describe the solution you'd like I would like the middleware to be enhanced so that it properly handles and propagates errors even when compression is applied. This means ensuring that Error(StatusError) in ResBody is recognized and processed correctly by the compression middleware. Ideally, the middleware should check for errors in the response body before applying compression and handle them appropriately to ensure that error handling is not bypassed.

Describe alternatives you've considered Changing the order of middleware

fankaiLiu commented 5 days ago

👍👍👍