Summary: Ref T1806. Ref T7173. Context here is that I want to fix "you can not log in to this instance" being a confusing mess with an opaque error. To do this without hacks, I want to: - clean up some exception handling behavior (this diff); - modularize exception handling (next diff); - replace confusing, over-general exceptions with tailored ones in the Phacility cluster, using the new modular stuff. This cleans up an awkward "AphrontUsageException" which does some weird stuff right now. In particular, it is extensible and extended in one place in Diffusion, but that extension is meaningless. Realign this as "AphrontMalformedRequestException", which is a better description of what it is and does: raises errors before we can get as far as normal routing and site handling. Test Plan: Hit some of these exceptions, saw the expected "abandon all hope" error page. Reviewers: chad Reviewed By: chad Maniphest Tasks: T1806, T7173 Differential Revision: https://secure.phabricator.com/D14047
95 lines
1.9 KiB
PHP
95 lines
1.9 KiB
PHP
<?php
|
|
|
|
final class AphrontUnhandledExceptionResponse
|
|
extends AphrontStandaloneHTMLResponse {
|
|
|
|
private $exception;
|
|
|
|
public function setException(Exception $exception) {
|
|
// Log the exception unless it's specifically a silent malformed request
|
|
// exception.
|
|
|
|
$should_log = true;
|
|
if ($exception instanceof AphrontMalformedRequestException) {
|
|
if ($exception->getIsUnlogged()) {
|
|
$should_log = false;
|
|
}
|
|
}
|
|
|
|
if ($should_log) {
|
|
phlog($exception);
|
|
}
|
|
|
|
$this->exception = $exception;
|
|
return $this;
|
|
}
|
|
|
|
public function getHTTPResponseCode() {
|
|
return 500;
|
|
}
|
|
|
|
protected function getResources() {
|
|
return array(
|
|
'css/application/config/config-template.css',
|
|
'css/application/config/unhandled-exception.css',
|
|
);
|
|
}
|
|
|
|
protected function getResponseTitle() {
|
|
$ex = $this->exception;
|
|
|
|
if ($ex instanceof AphrontMalformedRequestException) {
|
|
return $ex->getTitle();
|
|
} else {
|
|
return pht('Unhandled Exception');
|
|
}
|
|
}
|
|
|
|
protected function getResponseBodyClass() {
|
|
return 'unhandled-exception';
|
|
}
|
|
|
|
protected function getResponseBody() {
|
|
$ex = $this->exception;
|
|
|
|
if ($ex instanceof AphrontMalformedRequestException) {
|
|
$title = $ex->getTitle();
|
|
} else {
|
|
$title = get_class($ex);
|
|
}
|
|
|
|
$body = $ex->getMessage();
|
|
$body = phutil_escape_html_newlines($body);
|
|
|
|
return phutil_tag(
|
|
'div',
|
|
array(
|
|
'class' => 'unhandled-exception-detail',
|
|
),
|
|
array(
|
|
phutil_tag(
|
|
'h1',
|
|
array(
|
|
'class' => 'unhandled-exception-title',
|
|
),
|
|
$title),
|
|
phutil_tag(
|
|
'div',
|
|
array(
|
|
'class' => 'unhandled-exception-body',
|
|
),
|
|
$body),
|
|
));
|
|
}
|
|
|
|
protected function buildPlainTextResponseString() {
|
|
$ex = $this->exception;
|
|
|
|
return pht(
|
|
'%s: %s',
|
|
get_class($ex),
|
|
$ex->getMessage());
|
|
}
|
|
|
|
}
|