Im implementing user API and want to return errors(400, 401, 403, 404) in json format. So how to change errorHandler setting if in REQUEST_URI exists some string?
Im implementing user API and want to return errors(400, 401, 403, 404) in json format. So how to change errorHandler setting if in REQUEST_URI exists some string?
Actually ive found a solution.
In action which handles errors for all project i just check if there is in current URL a strign which indicate that user called API ("/api" in my case). Then just call controller in my API module that returns error in json format:
if (strpos($_SERVER['REQUEST_URI'], '/api') === 0) { // user requested some from API so show error in json format
Yii::import('application.modules.api.controllers.ApiErrorController');
$c = new ApiErrorController('ApiError', 'api');
$c->actionIndex();
}
Hope it will userfull to somebody