mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 01:32:42 +01:00
1fc60a9a6e
Summary: Ref T1806. Ref T7173. Depends on D14047. Currently, all exception handling is in this big messy clump in `AphrontDefaultApplicationConfiguration`. Split it out into modular classes. This will let a future change add new classes in the Phacility cluster which intercept particular exceptions we care about and replaces the default, generic responses with more useful, tailored responses. Test Plan: {F777391} - Hit a Conduit error (made a method throw). - Hit an Ajax error (made comment preview throw). - Hit a high security error (tried to edit TOTP). - Hit a rate limiting error (added a bunch of email addresses). - Hit a policy error (tried to look at something with no permission). - Hit an arbitrary exception (made a randomc ontroller throw). Reviewers: chad Reviewed By: chad Maniphest Tasks: T1806, T7173 Differential Revision: https://secure.phabricator.com/D14049
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
final class PhabricatorRateLimitRequestExceptionHandler
|
|
extends PhabricatorRequestExceptionHandler {
|
|
|
|
public function getRequestExceptionHandlerPriority() {
|
|
return 300000;
|
|
}
|
|
|
|
public function getRequestExceptionHandlerDescription() {
|
|
return pht(
|
|
'Handles action rate limiting exceptions which occur when a user '.
|
|
'does something too frequently.');
|
|
}
|
|
|
|
public function canHandleRequestException(
|
|
AphrontRequest $request,
|
|
Exception $ex) {
|
|
|
|
if (!$this->isPhabricatorSite($request)) {
|
|
return false;
|
|
}
|
|
|
|
return ($ex instanceof PhabricatorSystemActionRateLimitException);
|
|
}
|
|
|
|
public function handleRequestException(
|
|
AphrontRequest $request,
|
|
Exception $ex) {
|
|
|
|
$viewer = $this->getViewer($request);
|
|
|
|
return id(new AphrontDialogView())
|
|
->setTitle(pht('Slow Down!'))
|
|
->setUser($viewer)
|
|
->setErrors(array(pht('You are being rate limited.')))
|
|
->appendParagraph($ex->getMessage())
|
|
->appendParagraph($ex->getRateExplanation())
|
|
->addCancelButton('/', pht('Okaaaaaaaaaaaaaay...'));
|
|
}
|
|
|
|
}
|