protected function _getErrorData()
    {
        $data = [];

        $viewVars = $this->controller->viewVars;
        if (!empty($viewVars['_serialize'])) {
            foreach ($viewVars['_serialize'] as $v) {
                $data[$v] = $viewVars[$v];
            }
        }

        if (!empty($viewVars['error']) && Configure::read('debug')) {
            $data['exception'] = [
                'class' => get_class($viewVars['error']),
                'code' => $viewVars['error']->getCode(),
                'message' => $viewVars['error']->getMessage(),
            ];

            if (!isset($data['trace'])) {
                $data['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), [
                    'format' => 'array',
                    'args' => false
                ]);
            }
        }

        return $data;
    }