From feac35a0fddcd66f4f78815284650d47f2017739 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 5 Mar 2014 12:07:39 -0800 Subject: [PATCH] Improve 404 behavior for new Diviner Summary: Ref T988. When the user clicks a link we haven't explicitly resolved before, we send them to the `/find/` endpoint, but currently just 404 if we can't find the relevant documentation. Instead, display a more user-friendly error message, since we're probably going to have some of these. Also, make the page title much worse. Test Plan: Hit a 404 via `/find/`, got a nicer page. Reviewers: chad, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T988 Differential Revision: https://secure.phabricator.com/D8408 --- .../controller/DivinerFindController.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/applications/diviner/controller/DivinerFindController.php b/src/applications/diviner/controller/DivinerFindController.php index e672a21f4b..56b6af89b7 100644 --- a/src/applications/diviner/controller/DivinerFindController.php +++ b/src/applications/diviner/controller/DivinerFindController.php @@ -11,6 +11,7 @@ final class DivinerFindController extends DivinerController { $viewer = $request->getUser(); $book_name = $request->getStr('book'); + $query_text = $request->getStr('name'); $book = null; if ($book_name) { @@ -44,22 +45,33 @@ final class DivinerFindController extends DivinerController { $name_query->withNames( array( - $request->getStr('name'), + $query_text, // TODO: This could probably be more smartly normalized in the DB, // but just fake it for now. - phutil_utf8_strtolower($request->getStr('name')), + phutil_utf8_strtolower($query_text), )); $atoms = $name_query->execute(); if (!$atoms) { $title_query = clone $query; - $title_query->withTitles(array($request->getStr('name'))); + $title_query->withTitles(array($query_text)); $atoms = $title_query->execute(); } + $not_found_uri = $this->getApplicationURI(); + if (!$atoms) { - return new Aphront404Response(); + $dialog = id(new AphrontDialogView()) + ->setUser($viewer) + ->setTitle(pht('Documentation Not Found')) + ->appendChild( + pht( + 'Unable to find the specified documentation. You may have '. + 'followed a bad or outdated link.')) + ->addCancelButton($not_found_uri, pht('Read More Documentation')); + + return id(new AphrontDialogResponse())->setDialog($dialog); } if (count($atoms) == 1 && $request->getBool('jump')) { @@ -72,7 +84,7 @@ final class DivinerFindController extends DivinerController { return $this->buildApplicationPage( $list, array( - 'title' => 'derp', + 'title' => array(pht('Find'), pht('"%s"', $query_text)), 'device' => true, )); }