Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/response/AphrontUnhandledExceptionResponse.php
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | if ($ex instanceof AphrontMalformedRequestException) { | ||||
return pht('Unhandled Exception'); | return pht('Unhandled Exception'); | ||||
} | } | ||||
} | } | ||||
protected function getResponseBodyClass() { | protected function getResponseBodyClass() { | ||||
return 'unhandled-exception'; | return 'unhandled-exception'; | ||||
} | } | ||||
private function getExceptionList() { | |||||
return $this->expandException($this->exception); | |||||
} | |||||
private function expandException($root) { | |||||
if ($root instanceof PhutilAggregateException) { | |||||
$list = array(); | |||||
$list[] = $root; | |||||
foreach ($root->getExceptions() as $ex) { | |||||
foreach ($this->expandException($ex) as $child) { | |||||
$list[] = $child; | |||||
} | |||||
} | |||||
return $list; | |||||
} | |||||
return array($root); | |||||
} | |||||
protected function getResponseBody() { | protected function getResponseBody() { | ||||
$ex = $this->exception; | $body = array(); | ||||
foreach ($this->getExceptionList() as $ex) { | |||||
$body[] = $this->newHTMLMessage($ex); | |||||
} | |||||
return $body; | |||||
} | |||||
private function newHTMLMessage($ex) { | |||||
if ($ex instanceof AphrontMalformedRequestException) { | 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); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | return phutil_tag( | ||||
'class' => 'unhandled-exception-body', | 'class' => 'unhandled-exception-body', | ||||
), | ), | ||||
$body), | $body), | ||||
$stack, | $stack, | ||||
)); | )); | ||||
} | } | ||||
protected function buildPlainTextResponseString() { | protected function buildPlainTextResponseString() { | ||||
$ex = $this->exception; | $messages = array(); | ||||
foreach ($this->getExceptionList() as $exception) { | |||||
$messages[] = $this->newPlainTextMessage($exception); | |||||
} | |||||
return implode("\n\n", $messages); | |||||
} | |||||
private function newPlainTextMessage($exception) { | |||||
return pht( | return pht( | ||||
'%s: %s', | '%s: %s', | ||||
get_class($ex), | get_class($exception), | ||||
$ex->getMessage()); | $exception->getMessage()); | ||||
} | } | ||||
} | } |