ErrorController.php 999 Bytes
<?php
/**
 *  This is error handler configured as global
 * 
 */

class ErrorController extends WRestController
{
    public function actionError() {
        if($error = Yii::app()->errorHandler->error) {
            if(YII_DEBUG) {
                $this->sendResponse($error['code'], array(
                    'success' => false,
                    'error' => $error
                ));
            }
            else {
                if(Yii::app()->user->isGuest) {
                    $this->sendResponse(401, array(
                        'success' => false
                    ));
                }
                else {
                    $this->sendResponse($error['code'], array(
                        'success' => false,
                        'error' =>  array(
                            'message' => $error['message']
                        ))
                    );
                }
            }
        }
        else {
            Yii::app()->end();
        }
    }
}