ZF2 - Error handling for a specific module only

I have a multi-module application.

And one of its modules listens for "dispatch.error" with a priority of 999. And it seems to break errors from all other modules.

I need to catch the error only in my specific module and behave accordingly. It will work if, for example, I listen to "dispatch.error" with a priority of 1000 and filter errors specific to my module (by exception names or using route filtering), but there is no guarantee that any other module will not have 10,000 priority for the same event.

I am new to ZF2 and don't know if there is a way to solve this problem.

This question seems to be the same: ZF2: How to connect a special module listener for dispatch.error , but the answer does not help at all, although it is accepted.

Update: I found out that this can be fixed by changing DispatchListener.php (when using a user id inside SharedEventManager ).

DispatchListener receives an EventManager as follows:

 $events = $application->getEventManager(); 

But if the controller exists, this can be overridden:

 $events = $controller->getEventManager(); 

And then the problem with modular error handlers will be solved.

Does anyone know the solutions without fixing the core files? And actually this is a mistake (this user module can listen to "send", for example, but cannot listen to "dispatch.error")

0
source share

Source: https://habr.com/ru/post/1494298/


All Articles