protected function _addDebugNode($json)
    {
        $viewVars = $this->controller->viewVars;

        if (empty($viewVars['error'])) {
            return $json;
        }

        $debug = [];
        $debug['class'] = get_class($viewVars['error']);

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

        $result = json_decode($json, true);
        $result['debug'] = $debug;

        try {
            return json_encode($result, JSON_PRETTY_PRINT);
        } catch (\Exception $e) {
            $result['debug']['message'] = $e->getMessage();
            $result['debug']['trace'] = [
                'error' => 'Unable to encode stack trace',
            ];

            return json_encode($result, JSON_PRETTY_PRINT);
        }
    }