protected function convertExceptionToArray($exception)
    {
        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
        }

        $array = [
            'code' => $exception->getCode(),
            'data' => new \stdClass(),
            'message' => $exception->getMessage(),
        ];
        if ($exception instanceof HttpException) {
            $array['code'] = $exception->statusCode;
        }
        if($exception instanceof ApiException && !empty($exception->model)){
            $array = [
                'code' => 422,
                'data' => $exception->model->getErrors(),
                'message' => 'Data Validation Failed.',
            ];
        }
        if (YII_DEBUG) {
            $array['type'] = get_class($exception);
            if (!$exception instanceof UserException) {
                $array['file'] = $exception->getFile();
                $array['line'] = $exception->getLine();
                $array['stack-trace'] = explode("\n", $exception->getTraceAsString());
                if ($exception instanceof \yii\db\Exception) {
                    $array['error-info'] = $exception->errorInfo;
                }
            }
            if (($prev = $exception->getPrevious()) !== null) {
                $array['previous'] = $this->convertExceptionToArray($prev);
            }
        }

        return $array;
    }
protected function convertExceptionToArray($exception)
    {
        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
        }

        $array = [
            'code' => $exception->getCode(),
            'data' => new \stdClass(),
            'message' => $exception->getMessage(),
        ];
        if ($exception instanceof HttpException) {
            $array['code'] = $exception->statusCode;
        }
        if($exception instanceof ApiException && !empty($exception->model)){
            $array = [
                'code' => 422,
                'data' => $exception->model->getErrors(),
                'message' => 'Data Validation Failed.',
            ];
        }
        if (YII_DEBUG) {
            $array['type'] = get_class($exception);
            if (!$exception instanceof UserException) {
                $array['file'] = $exception->getFile();
                $array['line'] = $exception->getLine();
                $array['stack-trace'] = explode("\n", $exception->getTraceAsString());
                if ($exception instanceof \yii\db\Exception) {
                    $array['error-info'] = $exception->errorInfo;
                }
            }
            if (($prev = $exception->getPrevious()) !== null) {
                $array['previous'] = $this->convertExceptionToArray($prev);
            }
        }

        return $array;
    }
protected function convertExceptionToArray ( $ exception ) { if ( ! YII_DEBUG && ! $ exception instanceof UserException && ! $ exception instanceof HttpException ) { $ exception = new HttpException ( 500 , Yii :: t ( 'yii' , 'An internal server error occurred.' ) ) ; } $ array = [ 'code' => $ exception -> getCode ( ) , 'data' => new \ stdClass ( ) , 'message' => $ exception -> getMessage ( ) , ] ; if ( $ exception instanceof HttpException ) { $ array [ 'code' ] = $ exception -> statusCode ; } if ( $ exception instanceof ApiException && ! empty ( $ exception -> model ) ) { $ array = [ 'code' => 422 , 'data' => $ exception -> model -> getErrors ( ) , 'message' => 'Data Validation Failed.' , ] ; } if ( YII_DEBUG ) { $ array [ 'type' ] = get_class ( $ exception ) ; if ( ! $ exception instanceof UserException ) { $ array [ 'file' ] = $ exception -> getFile ( ) ; $ array [ 'line' ] = $ exception -> getLine ( ) ; $ array [ 'stack-trace' ] = explode ( "\n" , $ exception -> getTraceAsString ( ) ) ; if ( $ exception instanceof \ yii \ db \ Exception ) { $ array [ 'error-info' ] = $ exception -> errorInfo ; } } if ( ( $ prev = $ exception -> getPrevious ( ) ) !== null ) { $ array [ 'previous' ] = $ this -> convertExceptionToArray ( $ prev ) ; } } return $ array ; }
Converts an exception into an array.
@param \Exception $exception the exception being converted
@return array the array representation of the exception.
Converts an exception into an array .