Where in the application can you or should you call such a method so that, with any db error, send yourself an email with an error code message?
- It makes sense, if not connected, and in other cases, is it necessary? Catch an exception if there is no connection and send a notification. - fedornabilkin
- Yes, there the data goes automatically, and if the base "falls off" then it is desirable to know about it. I understand that you need to catch db exception, I do not understand where it should be done - ProMix
|
1 answer
Several options. One of the simplest is to create your own action, to which to send requests with exceptions. By default, the path is defined in Yii2 in the config.
'components' => [ 'errorHandler' => [ 'errorAction' => 'site/error', ], ]
In the controller, respectively, specify the class that will handle this action.
public function actions() { return [ 'error' => [ 'class' => 'CustomErrorAction', ], ]; }
We inherit our class from the default yii yii\web\ErrorAction
and in the init () method of our class (first calling the parent method), we can catch the necessary exception and trigger the necessary events or method that will send the notification.
|