pmallinj•

Hi, I see you use a response factory to produce default responses when method not allowed or not found. My take on this is exceptions should be thrown instead, because it allows developers using your library to catch them with another middleware to produce any response they want. Here we don't have the choice how to deal with those errors. What are your thoughts about this?

5
ShadowhandOP•

In the context of routing I do not believe using exceptions is the right approach. Middleware has access to the response and can check the status and modify before returning it.

This is a situation where adding exceptions would be using exceptions for flow control and would actually interrupt normal middleware processing.

3
pmallinj•

Right I didn't think about using the response status. Pretty nice.

Then, how would you deal with exceptions producing 500 responses? Let's say the request handler matched by the router try to connect to a database and something goes wrong. Would you directly produce a response from the request handler or would you use a catch-all middleware in this case?

1
ShadowhandOP•

A catch all middleware, or a global exception handler, to handle exceptions that for cough exceptional situations.

2
pmallinj•

Ok thanks for the insight. By the way nice to talk with you, I learnt many things by following your work!

2