Skip to content

Commit

Permalink
Use interface to determine if an exception contains HTML message cont…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
diosmosis committed Oct 29, 2014
1 parent 9c8be50 commit 8e274dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
12 changes: 2 additions & 10 deletions core/Exceptions/HtmlMessageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@
*
* @api
*/
class HtmlMessageException extends Exception
class HtmlMessageException extends Exception implements HtmlMessageExceptionInterface
{
/**
* Returns the exception message.
*
* @return string
*/
public function getHtmlMessage()
{
return $this->getMessage();
}
// empty
}
20 changes: 20 additions & 0 deletions core/Exceptions/HtmlMessageExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Exceptions;

/**
* Exceptions that implement this interface are assumed to have HTML content
* in their messages.
*
* @api
*/
interface HtmlMessageExceptionInterface
{
// empty
}
5 changes: 3 additions & 2 deletions core/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Piwik\API\Request;
use Piwik\API\ResponseBuilder;
use Piwik\Exceptions\HtmlMessageException;
use Piwik\Exceptions\HtmlMessageExceptionInterface;
use Piwik\Http\Router;
use Piwik\Plugin\Controller;
use Piwik\Plugin\Report;
Expand Down Expand Up @@ -613,8 +614,8 @@ public function getErrorResponse(Exception $ex)
{
$debugTrace = $ex->getTraceAsString();

if (method_exists($ex, 'getHtmlMessage')) {
$message = $ex->getHtmlMessage();
if ($ex instanceof HtmlMessageExceptionInterface) {
$message = $ex->getMessage();
} else {
$message = Common::sanitizeInputValue($ex->getMessage());
}
Expand Down

0 comments on commit 8e274dd

Please sign in to comment.