Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/response/AphrontUnhandledExceptionResponse.php
<?php | <?php | ||||
final class AphrontUnhandledExceptionResponse | final class AphrontUnhandledExceptionResponse | ||||
extends AphrontStandaloneHTMLResponse { | extends AphrontStandaloneHTMLResponse { | ||||
private $exception; | private $exception; | ||||
private $showStackTraces; | |||||
public function setShowStackTraces($show_stack_traces) { | |||||
$this->showStackTraces = $show_stack_traces; | |||||
return $this; | |||||
} | |||||
public function getShowStackTraces() { | |||||
return $this->showStackTraces; | |||||
} | |||||
public function setException($exception) { | |||||
// NOTE: We accept an Exception or a Throwable. | |||||
public function setException(Exception $exception) { | |||||
// Log the exception unless it's specifically a silent malformed request | // Log the exception unless it's specifically a silent malformed request | ||||
// exception. | // exception. | ||||
$should_log = true; | $should_log = true; | ||||
if ($exception instanceof AphrontMalformedRequestException) { | if ($exception instanceof AphrontMalformedRequestException) { | ||||
if ($exception->getIsUnlogged()) { | if ($exception->getIsUnlogged()) { | ||||
$should_log = false; | $should_log = false; | ||||
} | } | ||||
Show All 39 Lines | if ($ex instanceof AphrontMalformedRequestException) { | ||||
$title = $ex->getTitle(); | $title = $ex->getTitle(); | ||||
} else { | } else { | ||||
$title = get_class($ex); | $title = get_class($ex); | ||||
} | } | ||||
$body = $ex->getMessage(); | $body = $ex->getMessage(); | ||||
$body = phutil_escape_html_newlines($body); | $body = phutil_escape_html_newlines($body); | ||||
$classes = array(); | |||||
$classes[] = 'unhandled-exception-detail'; | |||||
$stack = null; | |||||
if ($this->getShowStackTraces()) { | |||||
try { | |||||
$stack = id(new AphrontStackTraceView()) | |||||
->setTrace($ex->getTrace()); | |||||
$stack = hsprintf('%s', $stack); | |||||
$stack = phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'unhandled-exception-stack', | |||||
), | |||||
$stack); | |||||
$classes[] = 'unhandled-exception-with-stack'; | |||||
} catch (Exception $trace_exception) { | |||||
$stack = null; | |||||
} catch (Throwable $trace_exception) { | |||||
$stack = null; | |||||
} | |||||
} | |||||
return phutil_tag( | return phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'unhandled-exception-detail', | 'class' => implode(' ', $classes), | ||||
), | ), | ||||
array( | array( | ||||
phutil_tag( | phutil_tag( | ||||
'h1', | 'h1', | ||||
array( | array( | ||||
'class' => 'unhandled-exception-title', | 'class' => 'unhandled-exception-title', | ||||
), | ), | ||||
$title), | $title), | ||||
phutil_tag( | phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'unhandled-exception-body', | 'class' => 'unhandled-exception-body', | ||||
), | ), | ||||
$body), | $body), | ||||
$stack, | |||||
)); | )); | ||||
} | } | ||||
protected function buildPlainTextResponseString() { | protected function buildPlainTextResponseString() { | ||||
$ex = $this->exception; | $ex = $this->exception; | ||||
return pht( | return pht( | ||||
'%s: %s', | '%s: %s', | ||||
get_class($ex), | get_class($ex), | ||||
$ex->getMessage()); | $ex->getMessage()); | ||||
} | } | ||||
} | } |