ErrorHandling handle exception thrown by ActionController $this->throwStatus

Hello all!

(seems I’m alone in this category? :wink: )

In my API I’m using a custom error handling descriped under Error and Exception Handling — Flow Framework 9.2.x documentation

This works fine with status code 401, 404 and 403

In my API an error 422 exists which is thrown in an ActionController with

$this->throwStatus(422, 'unprocessable content', 'no data');

This error is not handled in my instance of Neos\Flow\Error\ProductionExceptionHandler

In global Seetings.yaml an apropriate definition exists.

error:
  exceptionHandler:
    renderingGroups:
      datasetMismatchExceptions:
        matchingStatusCodes: [422]
        options: ...

Flow cache was flushed and so on..

What I’m doing wrong?

Hi Frank,

(yes it seems very much but don’t worry i like to help^^)

I dont know about the historic reasoning of throwStatus() but when you look at the implementation you see that it builds up the HTTP Response and then tells the Flow Dispatcher to send that via the StopActionException.

When you refer to rendering groups and exception handlers we intend to catch an Exception in the outmost layers. The exception must be of type \Neos\Flow\Exception (probably an inheritor), and here the property $statusCode must be set. That way the error handler registered by Flow catches that exception and does the handling.

Indeed its a bit weird how throwStatus() comes into play but it does not trigger the behaviour as we catch the exception earlier and trigger an immediate HTTP Response.

Maybe @kdambekalns or @christianm can shed light into why we have this kind-of two ways to do a similar thing.

Hello Marc!

Very interresting “interrelations” indeed…

In a very early version of my controller I’ve used simply $this->response->setStatusCode(422) but later there was an deprication notice - if I remember correctly.

Next days I will try to throw an \Neos\Flow\Exception and report the result here.

Thanx, Marc!