middlewares/fast-route

404 and 405

mav2287 opened this issue · 3 comments

Are there any code examples of how to implement the 404 and 405 custom errors? Also are there any examples are how to implement things like 301 redirect responses in connection with the return?

The scope of this middleware is just storing the request handler assigned to the current route and run the next middeware, but without executing it.

For 404 and 405 responses you can use ErrorResponse, that allows to assign a custom body to the response (for example a json error or a html page).

Thanks. The reason I was asking is the docs say "Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument, that will be used to create the error responses (404 or 405). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.", but there is no further instruction there on how to do it.

Ah, I understand.
This is to add a different factory to create the Response instance for 404 and 405 reponses. By default detects automatically the popular libraries Diactoros, Guzzle, Slim, Nyholm/psr7 and Sunrise but if you are using a different PSR7 library, you can include the factory here. In any case, the response generated is empty.