I have this module which works mainly as a JSON provider to client side.
I wish all exceptions in the controller actions will be caught internally, handled (logged) and a nicely formatted JSON error message will be sent to client side.
What would you recommend in order to achieve this?
In this controller (in the init function for example) you can change the error action of Yii::app()->errorHandler to an action of the controller itself that sends a json formatted exception.
But I’m thinking - changing Yii::app()->errorHandler will affect anything that runs in this request right? I mean, if I have some method that runs at the end of the request, such as CApplication->onEndRequest(), it will run always with the modified error handler right?
I can use this solution but if I’m right above (with regard to other methods running on the same request) then this is not the cleanest solution. Maybe it doesn’t get any cleaner but that’s exactly the question…
I think that mere setting of Yii::app()->errorHandler->errorAction to a route in the specific controller is even sleeker since its less intrusive - no need to provide a complete error handler replacement component but rather only an action method.
I already implemented this as an extension which I’m uploading as I write this, since I wasn’t sure if Yii supports returning back to request processing after the method pointed by errorAction is being run.