Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15414876
D20720.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D20720.diff
View Options
diff --git a/src/aphront/configuration/AphrontApplicationConfiguration.php b/src/aphront/configuration/AphrontApplicationConfiguration.php
--- a/src/aphront/configuration/AphrontApplicationConfiguration.php
+++ b/src/aphront/configuration/AphrontApplicationConfiguration.php
@@ -312,11 +312,17 @@
if ($response_exception) {
// If we encountered an exception while building a normal response, then
// encountered another exception while building a response for the first
- // exception, just throw the original exception. It is more likely to be
- // useful and point at a root cause than the second exception we ran into
- // while telling the user about it.
+ // exception, throw an aggregate exception that will be unpacked by the
+ // higher-level handler. This is above our pay grade.
if ($original_exception) {
- throw $original_exception;
+ throw new PhutilAggregateException(
+ pht(
+ 'Encountered a processing exception, then another exception when '.
+ 'trying to build a response for the first exception.'),
+ array(
+ $response_exception,
+ $original_exception,
+ ));
}
// If we built a response successfully and then ran into an exception
diff --git a/src/aphront/response/AphrontUnhandledExceptionResponse.php b/src/aphront/response/AphrontUnhandledExceptionResponse.php
--- a/src/aphront/response/AphrontUnhandledExceptionResponse.php
+++ b/src/aphront/response/AphrontUnhandledExceptionResponse.php
@@ -61,9 +61,39 @@
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() {
- $ex = $this->exception;
+ $body = array();
+
+ foreach ($this->getExceptionList() as $ex) {
+ $body[] = $this->newHTMLMessage($ex);
+ }
+
+ return $body;
+ }
+ private function newHTMLMessage($ex) {
if ($ex instanceof AphrontMalformedRequestException) {
$title = $ex->getTitle();
} else {
@@ -122,12 +152,20 @@
}
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(
'%s: %s',
- get_class($ex),
- $ex->getMessage());
+ get_class($exception),
+ $exception->getMessage());
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 21, 2:56 AM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7550037
Default Alt Text
D20720.diff (2 KB)
Attached To
Mode
D20720: When a page throws an exception and response construction throws another exception, throw an aggregate exception
Attached
Detach File
Event Timeline
Log In to Comment