<?php
/**
 * Created by PhpStorm.
 * User: Alex
 * Date: 14/04/2019
 * Time: 12:48
 */

namespace vr\api\components;

use Error;
use Exception;
use vr\core\ErrorsException;
use Yii;

/**
 * Class ErrorHandler
 * @package vr\api\components
 */
class ErrorHandler extends \yii\web\ErrorHandler
{
    /**
     * @var int
     */
    public $errorStatusCode = 400;

    /**
     * @param Error|Exception $exception
     *
     * @return array
     */
    protected function convertExceptionToArray($exception)
    {
        $array = parent::convertExceptionToArray($exception);

        if ($exception instanceof ErrorsException) {
            Yii::$app->response->statusCode = $this->errorStatusCode;

            $array += [
                'data' => $exception->data,
            ];

            if (YII_DEBUG) {
                $array += [
                    'trace' => explode("\n", $exception->getTraceAsString())
                ];
            }
        }

        return $array;
    }
}
<?php
/**
 * Created by PhpStorm.
 * User: Alex
 * Date: 14/04/2019
 * Time: 12:48
 */

namespace vr\api\components;

use Error;
use Exception;
use vr\core\ErrorsException;

/**
 * Class ErrorHandler
 * @package vr\api\components
 */
class ErrorHandler extends \yii\web\ErrorHandler
{
    /**
     * @param Error|Exception $exception
     *
     * @return array
     */
    protected function convertExceptionToArray($exception)
    {
        $array = parent::convertExceptionToArray($exception);

        if ($exception instanceof ErrorsException) {
            $array += [
                'data' => $exception->data,
            ];

            if (YII_DEBUG) {
                $array += [
                    'trace' => explode("\n", $exception->getTraceAsString())
                ];
            }
        }

        return $array;
    }
}
--- 
+++ 
@@ -11,6 +11,7 @@
 use Error;
 use Exception;
 use vr\core\ErrorsException;
+use Yii;
 
 /**
  * Class ErrorHandler
@@ -18,6 +19,11 @@
  */
 class ErrorHandler extends \yii\web\ErrorHandler
 {
+    /**
+     * @var int
+     */
+    public $errorStatusCode = 400;
+
     /**
      * @param Error|Exception $exception
      *
@@ -28,6 +34,8 @@
         $array = parent::convertExceptionToArray($exception);
 
         if ($exception instanceof ErrorsException) {
+            Yii::$app->response->statusCode = $this->errorStatusCode;
+
             $array += [
                 'data' => $exception->data,
             ];
Add ability to change the response status code on ErrorsException
