EmbarkStudios / server-framework

Framework for running network services, opinions included
Apache License 2.0
36 stars 4 forks source link

Fix middleware ordering if someone called unknown route #21

Closed davidpdrsn closed 2 years ago

davidpdrsn commented 2 years ago

Checklist

Description of Changes

If someone called a route that didn't exist we would return 500 because a tower_http::request_id::RequestId couldn't be found in request extensions. That happened because the error handling middleware (which is invoked on timeouts and other middleware errors) tried to extract it. However the extension would be set inside a route_layer which is only called if there is a matching route. So if someone called route that didn't exist the request id extension would be missing and cause the error.

The solution is to reorder the middleware such that request ids are always set.

I have tested this with our internal services and verified that it does actually work.

Related Issues

List related issues here