Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Yii2 and Exceptions #3431
I'm goind to build REST API for my app, based on Yii2. So, i have a problem with exceptions. For example, i need to throw 405 HTTP code when someone use wrong HTTP verb, but i wanna send back something like this:
So, i need to catch HttpException, recognize type of error and modify Response object. But how can i do this? In Yii there were onError and onException events. What about Yii2?
I did this, but when i try to change errorHandler component in my API module i get nothing.
\Yii::$app->set('errorHandler',array( 'class'=>'app\components\ApiErrorHandler', 'errorAction'=>'site/error', ));
\yii\web\ErrorHandler still working. I need to re-init component somehow....