Answer the question
In order to leave comments, you need to log in
How to properly configure error output in Yii2 api?
I am writing a site api on a separate domain api.site.ru I
use the basic template, controllers and api models are placed in the modules/v1/ folder
For example, when requesting a non-existent page api.site.ru/asdqwe, the server gives a 404 error, but along with html code, even through the console.
How to override and display errors without a template and html code?
Answer the question
In order to leave comments, you need to log in
Apparently you need to configure response. If everywhere, then through the config, if in a specific action, then you can do this:
Yii::$app->response->format = Response::FORMAT_JSON;
Yii::$app->response->setStatusCode(404,'Вы запросили не существующую хрень'));
return false;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question