As usual, Yii2 shows errors in HTML format in site/error file. How to make all errors returned as JSON format?
You could change the format of your response in a certain action of your controller, for example:
public function actionYourAction($id_survey) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
// return JSON Array or JSON Object here.
}
But in your case, you must first overwrite the error action, as explained here: https://www.yiiframework.com/doc/api/2.0/yii-web-erroraction