public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $ex = $this->getException(); if ($ex instanceof UserException) { $obj = ['message' => $ex->getMessage(), 'code' => $ex->getUserErrorCode(), 'status' => $ex->getCode()]; } else { if ($this->debug) { $obj = ['message' => $ex->getMessage(), 'code' => $ex->getCode(), 'status' => 500]; } else { $obj = ['message' => 'Server internal error', 'code' => -1, 'status' => 500]; } } if ($this->debug) { $obj['detail'] = Formatter::formatExceptionAsDataArray($this->getInspector(), true); } $this->getRun()->sendHttpCode($obj['status']); if (Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($obj); return Handler::QUIT; }
public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $display = Config::get('concrete.debug.display_errors'); if (!$display) { $error = array('message' => t('An error occurred while processing this request.')); } else { $detail = Config::get('concrete.debug.detail', 'message'); if ($detail !== 'debug') { $e = $this->getInspector()->getException(); $error = array('message' => $e->getMessage()); } else { $error = Formatter::formatExceptionAsDataArray($this->getInspector(), true); } } $response = array('error' => $error, 'errors' => array($error['message'])); if (Misc::canSendHeaders()) { if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-Type: application/json; charset=' . APP_CHARSET, true); } else { header('Content-Type: text/plain; charset=' . APP_CHARSET, true); } } echo json_encode($response); return Handler::QUIT; }
public function testPlain() { $msg = 'Sample exception message foo'; $output = Formatter::formatExceptionPlain(new Inspector(new \Exception($msg))); $this->assertContains($msg, $output); $this->assertContains('Stacktrace', $output); }
/** * @return int|null */ public function handle() { if (!$this->handleUnconditionally()) { // Check conditions for outputting HTML: // @todo: Make this more robust if (php_sapi_name() === 'cli') { // Help users who have been relying on an internal test value // fix their code to the proper method if (isset($_ENV['whoops-test'])) { throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable'); } return Handler::DONE; } } $exception = func_get_arg(0); // @todo: Make this more dynamic $helper = new TemplateHelper(); $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); $zeptoFile = $this->getResource("js/zepto.min.js"); $jsFile = $this->getResource("js/whoops.base.js"); if ($this->customCss) { $customCssFile = $this->getResource($this->customCss); } $inspector = $this->getInspector(); $frames = $inspector->getFrames(); $code = $inspector->getException()->getCode(); if ($inspector->getException() instanceof \ErrorException) { // ErrorExceptions wrap the php-error types within the "severity" property $code = Misc::translateErrorCode($inspector->getException()->getSeverity()); } // List of variables that will be passed to the layout template. $vars = array("page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "tables" => array("Server/Request Data" => $_SERVER, "GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Environment Variables" => $_ENV)); if (isset($customCssFile)) { $vars["stylesheet"] .= file_get_contents($customCssFile); } // Add extra entries list of data tables: // @todo: Consolidate addDataTable and addDataTableCallback $extraTables = array_map(function ($table) { return $table instanceof \Closure ? $table() : $table; }, $this->getDataTables()); $vars["tables"] = array_merge($extraTables, $vars["tables"]); $helper->setVariables($vars); ob_start(); $helper->render($templateFile); $content = ob_get_clean(); $pathMatches = (bool) preg_match('/phalcon-debugbar/', $exception->getFile()); if (is_object($this->di) && !$pathMatches) { try { $response = $this->di['response']->setContent($content); $response = $this->di['debugbar']->modifyResponse($response); $content = $response->getContent(); } catch (\Exception $e) { } } echo $content; return Handler::QUIT; }
/** * @return int */ public function handle() { $response = Formatter::formatExceptionAsDataArray($this->getInspector(), 1); $viewModel = new ViewModel(); $viewModel->setTemplate('error/500'); $viewModel->setVariables($response); echo $this->renderer->render($viewModel); return \Whoops\Handler\Handler::QUIT; }
/** * @return int */ public function handle() { $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0); return Handler::QUIT; }
/** * @return int */ public function handle() { $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); $debug = $this->getDataTable(); if (count($debug) > 0) { $response["debug"] = $debug; } echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0); return Handler::QUIT; }
/** * @return int */ public function handle() { $response = Formatter::formatExceptionPlain($this->getInspector()); $debug = $this->getDataTable(); if (count($debug) > 0) { $response .= "\n\n" . json_encode(["debug" => $debug]); } $this->setProperHeader($this->getException()); echo $response; return Handler::QUIT; }
/** * @return int */ public function handle() { if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { return Handler::DONE; } $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($response); return Handler::QUIT; }
/** * @return int */ public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $response = array('success' => false, 'data' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (Misc::canSendHeaders()) { header('Content-Type: application/json; charset=' . get_option('blog_charset')); } $json_options = version_compare(PHP_VERSION, '5.4.0', '>=') ? JSON_PRETTY_PRINT : 0; echo wp_json_encode($response, $json_options); return Handler::QUIT; }
/** * @return int */ public function handle() { if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { return \Whoops\Handler\Handler::DONE; } if ($this->onlyForJsonRequests() && !$this->isJsonRequest()) { return \Whoops\Handler\Handler::DONE; } $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); unset($response['error']['file']); unset($response['error']['line']); $response['error']['code'] = $this->getException()->getCode(); if (\Whoops\Util\Misc::canSendHeaders()) { http_response_code($response['error']['code']); header('Content-Type: application/json'); } echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0); return \Whoops\Handler\Handler::QUIT; }
public function handle() { $debug = Config::get('concrete.debug.level', 0); if ($debug !== DEBUG_DISPLAY_ERRORS) { return Handler::DONE; } if (!$this->isAjaxRequest()) { return Handler::DONE; } $error = Formatter::formatExceptionAsDataArray($this->getInspector(), true); $response = array('error' => $error, 'errors' => array($error['message'])); if (\Whoops\Util\Misc::canSendHeaders()) { if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-Type: application/json; charset=' . APP_CHARSET, true); } else { header('Content-Type: text/plain; charset=' . APP_CHARSET, true); } } echo json_encode($response); return Handler::QUIT; }
/** * @return int */ public function handle() { $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); echo $this->toXml($response); return Handler::QUIT; }
/** * @return int|null */ public function handle() { if (!$this->handleUnconditionally()) { // Check conditions for outputting HTML: // @todo: Make this more robust if (php_sapi_name() === 'cli') { // Help users who have been relying on an internal test value // fix their code to the proper method if (isset($_ENV['whoops-test'])) { throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable'); } return Handler::DONE; } } // @todo: Make this more dynamic $helper = new TemplateHelper(); $cloner = new VarCloner(); // Only dump object internals if a custom caster exists. $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) { $class = $stub->class; $classes = [$class => $class] + class_parents($class) + class_implements($class); foreach ($classes as $class) { if (isset(AbstractCloner::$defaultCasters[$class])) { return $a; } } // Remove all internals return []; }]); $helper->setCloner($cloner); $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); $zeptoFile = $this->getResource("js/zepto.min.js"); $clipboard = $this->getResource("js/clipboard.min.js"); $jsFile = $this->getResource("js/whoops.base.js"); if ($this->customCss) { $customCssFile = $this->getResource($this->customCss); } $inspector = $this->getInspector(); $frames = $inspector->getFrames(); $code = $inspector->getException()->getCode(); if ($inspector->getException() instanceof \ErrorException) { // ErrorExceptions wrap the php-error types within the "severity" property $code = Misc::translateErrorCode($inspector->getException()->getSeverity()); } // List of variables that will be passed to the layout template. $vars = array("page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "clipboard" => file_get_contents($clipboard), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "tables" => array("GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Server/Request Data" => $_SERVER, "Environment Variables" => $_ENV)); if (isset($customCssFile)) { $vars["stylesheet"] .= file_get_contents($customCssFile); } // Add extra entries list of data tables: // @todo: Consolidate addDataTable and addDataTableCallback $extraTables = array_map(function ($table) { return $table instanceof \Closure ? $table() : $table; }, $this->getDataTables()); $vars["tables"] = array_merge($extraTables, $vars["tables"]); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: text/html'); } $helper->setVariables($vars); $helper->render($templateFile); return Handler::QUIT; }
public function getData($inspector) { //print_r($this->getInspector());exit(); $data = ['trace' => WhoopsFormatter::formatExceptionAsDataArray($inspector, $this->addTraceToOutput()), "GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : [], "Server/Request Data" => $_SERVER, "Environment Variables" => $_ENV]; return $data; }