Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/handler/PhabricatorDefaultRequestExceptionHandler.php
<?php | <?php | ||||
final class PhabricatorDefaultRequestExceptionHandler | final class PhabricatorDefaultRequestExceptionHandler | ||||
extends PhabricatorRequestExceptionHandler { | extends PhabricatorRequestExceptionHandler { | ||||
public function getRequestExceptionHandlerPriority() { | public function getRequestExceptionHandlerPriority() { | ||||
return 900000; | return 900000; | ||||
} | } | ||||
public function getRequestExceptionHandlerDescription() { | public function getRequestExceptionHandlerDescription() { | ||||
return pht('Handles all other exceptions.'); | return pht('Handles all other exceptions.'); | ||||
} | } | ||||
public function canHandleRequestException( | public function canHandleRequestThrowable( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
Exception $ex) { | $throwable) { | ||||
if (!$this->isPhabricatorSite($request)) { | if (!$this->isPhabricatorSite($request)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
public function handleRequestException( | public function handleRequestThrowable( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
Exception $ex) { | $throwable) { | ||||
$viewer = $this->getViewer($request); | $viewer = $this->getViewer($request); | ||||
// Some types of uninteresting request exceptions don't get logged, usually | // Some types of uninteresting request exceptions don't get logged, usually | ||||
// because they are caused by the background radiation of bot traffic on | // because they are caused by the background radiation of bot traffic on | ||||
// the internet. These include requests with bad CSRF tokens and | // the internet. These include requests with bad CSRF tokens and | ||||
// questionable "Host" headers. | // questionable "Host" headers. | ||||
$should_log = true; | $should_log = true; | ||||
if ($ex instanceof AphrontMalformedRequestException) { | if ($throwable instanceof AphrontMalformedRequestException) { | ||||
$should_log = !$ex->getIsUnlogged(); | $should_log = !$throwable->getIsUnlogged(); | ||||
} | } | ||||
if ($should_log) { | if ($should_log) { | ||||
phlog($ex); | phlog($throwable); | ||||
} | } | ||||
$class = get_class($ex); | $class = get_class($throwable); | ||||
$message = $ex->getMessage(); | $message = $throwable->getMessage(); | ||||
if ($ex instanceof AphrontSchemaQueryException) { | if ($throwable instanceof AphrontSchemaQueryException) { | ||||
$message .= "\n\n".pht( | $message .= "\n\n".pht( | ||||
"NOTE: This usually indicates that the MySQL schema has not been ". | "NOTE: This usually indicates that the MySQL schema has not been ". | ||||
"properly upgraded. Run '%s' to ensure your schema is up to date.", | "properly upgraded. Run '%s' to ensure your schema is up to date.", | ||||
'bin/storage upgrade'); | 'bin/storage upgrade'); | ||||
} | } | ||||
if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) { | if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) { | ||||
$trace = id(new AphrontStackTraceView()) | $trace = id(new AphrontStackTraceView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setTrace($ex->getTrace()); | ->setTrace($throwable->getTrace()); | ||||
} else { | } else { | ||||
$trace = null; | $trace = null; | ||||
} | } | ||||
$content = phutil_tag( | $content = phutil_tag( | ||||
'div', | 'div', | ||||
array('class' => 'aphront-unhandled-exception'), | array('class' => 'aphront-unhandled-exception'), | ||||
array( | array( | ||||
Show All 21 Lines |