From 8d3bb92b91abbe06f8fe9168bf30b206094a283e Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 25 Sep 2015 10:43:04 -0700 Subject: [PATCH] Make some Herald errors more spider-resistant Summary: Fixes T9328. There's no way to hit these error states by clicking things in the UI that I could find, but if you mash stuff into your URL bar or "Inspect Element..." and then edit the form to be full of garbage you can hit them. Make them a little more informative and don't send them to the log, since these are pretty much just fancy 404s. Test Plan: Bashed my fist on the URL bar to hit all these messages. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9328 Differential Revision: https://secure.phabricator.com/D14164 --- .../controller/HeraldRuleController.php | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index ce7a46cd00..37a583c7ef 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -24,6 +24,8 @@ final class HeraldRuleController extends HeraldController { } $cancel_uri = $this->getApplicationURI("rule/{$id}/"); } else { + $new_uri = $this->getApplicationURI('new/'); + $rule = new HeraldRule(); $rule->setAuthorPHID($viewer->getPHID()); $rule->setMustMatchAll(1); @@ -33,18 +35,40 @@ final class HeraldRuleController extends HeraldController { $rule_type = $request->getStr('rule_type'); if (!isset($rule_type_map[$rule_type])) { - $rule_type = HeraldRuleTypeConfig::RULE_TYPE_PERSONAL; + return $this->newDialog() + ->setTitle(pht('Invalid Rule Type')) + ->appendParagraph( + pht( + 'The selected rule type ("%s") is not recognized by Herald.', + $rule_type)) + ->addCancelButton($new_uri); } $rule->setRuleType($rule_type); - $adapter = HeraldAdapter::getAdapterForContentType( - $rule->getContentType()); + try { + $adapter = HeraldAdapter::getAdapterForContentType( + $rule->getContentType()); + } catch (Exception $ex) { + return $this->newDialog() + ->setTitle(pht('Invalid Content Type')) + ->appendParagraph( + pht( + 'The selected content type ("%s") is not recognized by '. + 'Herald.', + $rule->getContentType())) + ->addCancelButton($new_uri); + } if (!$adapter->supportsRuleType($rule->getRuleType())) { - throw new Exception( - pht( - "This rule's content type does not support the selected rule ". - "type.")); + return $this->newDialog() + ->setTitle(pht('Rule/Content Mismatch')) + ->appendParagraph( + pht( + 'The selected rule type ("%s") is not supported by the selected '. + 'content type ("%s").', + $rule->getRuleType(), + $rule->getContentType())) + ->addCancelButton($new_uri); } if ($rule->isObjectRule()) {