Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Requests with an unmatched route do not contain the RouteResult #344

@nesl247

Description

@nesl247

I found this bug when I was tracking down why an internal application was throwing an error in one of my post-route-matched middleware to configure NewRelic. To my surprise, a route that is not matched does not actually throw an exception.

I have two opinions on how to fix it.

The first option is that an exception should be thrown in Application::routeMiddleware() (https://github.com/zendframework/zend-expressive/blob/master/src/Application.php#L405) because the rest of the application is kinda done at this point. This is the option that I prefer because Application::dispatchMiddleware() (https://github.com/zendframework/zend-expressive/blob/master/src/Application.php#L446) already depends upon a RouteResult, thus one would likely have to have two routers both supported expressive in order for the second option to really make sense.

The other option is that this isn't done because technically the pipeline is still there, and anyone can have other middleware to handle a route. While this might be the case for some people, it seems really odd to have two routers that both would inject a RouteResult into the request.

If an exception is not the desired way to fix this, then we should really always inject the RouteResult into the request, and change dispatchMiddleware() to check isFailure() rather than just assuming the result being in the request means it was a success. The justification for this is that it is called RouteResult and even has a success property, indicating it does not guarantee a success.

The other benefit to use an exception is that all post-route-matched middleware in the pipeline don't have to make a check for whether or not the route was successful or not, as they probably shouldn't be executed anyways. If the exception isn't to be used, the comment in the middleware-pipeline.global.php should probably state that you should probably call the isFailure() method and and if it is true, return $next($request, $response) or throw an exception (if that's the intended behavior).

I would have submitted a PR for this, but since there are two ways to fix it, it's not worth submitting one if it won't be used due to the other method being preferred. Once discussed I can submit one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions