I initially liked this idea, but on a second thought I think this could
cause some major design issues.

First and foremost, http errors are not exactly exceptional. Every web
application produces negative responses, they're part of their normal life
cycle, so it could be said that this interface encourages using an
exception to control some flow that is actually part of how the application
is expected to work.

Secondarily, middlewares don't need another interface to model the errors
they produce, they can already use the responses, which have more than
enough to provide context to the outer layers: code, reason phrase and body.

Since one of the points of a middleware collection is to decouple the
stages of the request processing from each other, I think that offloading
this logic to a specific middleware with such a specific mechanic is an
implementation detail.
Now, many could have no problem with it per se, but I don't think
standardising it would be wise.

For example, the double catch block could completely avoided:

class ErrorHandler implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request,
DelegateInterface $delegate)
    {
        try {
            $response = $delegate->process($request);
        } catch (Exception $e) {
            //Generic error 500
            $response = $this->factory->createResponse(500);
            $this->logger->error('Unexpected error', compact($request,
$response, $e));
            return $response;
        }

        if ($this->debug and is_error($response)) {
            $this->logger->debug('Http Error', compact($request,
$response));
        }

        return $response;
    }
}

This way the error handler would be catching only truly unexpected errors,
the traditional 500s that make us freak out.
You certainly don't throw exceptions for 404s, do you? ;-)

Il giorno dom 9 apr 2017 alle ore 18:39 Michael Mayer <
[email protected]> ha scritto:

> Great idea, though support for `HttpErrorException` make sense for every
> PSR-7 framework, not only PSR-15.
>
> Thus, it has no dependence to middlewares and I see no reason to delay
> PSR-15 any further – it should be done in a new PSR.
>
> Bests,
> Michael Mayer
>
> On Sunday, April 9, 2017 at 4:08:26 PM UTC+2, Woody Gilk wrote:
>
> Anyone else from PSR-15 (proposed) WG have comments?
>
>
> Huh?
>
> --
> You received this message because you are subscribed to the Google Groups
> "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/235bad6d-dca0-46af-b66e-b9f0d5a2f5d2%40googlegroups.com
> <https://groups.google.com/d/msgid/php-fig/235bad6d-dca0-46af-b66e-b9f0d5a2f5d2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/CAFojS1v-c5YNw1Td77FX5TYghzLpGMovVe_QB2_0k4Dv8rDzqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to