More robust error handling in show-logo action
This commit is contained in:
parent
f6e23ab075
commit
14f37909d1
|
@ -42,3 +42,33 @@ class Application_Common_HTTPHelper
|
||||||
return $stationUrl;
|
return $stationUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ZendActionHttpException extends Exception {
|
||||||
|
|
||||||
|
private $_action;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Zend_Controller_Action $action
|
||||||
|
* @param int $statusCode
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
* @param Exception $previous
|
||||||
|
*
|
||||||
|
* @throws Zend_Controller_Response_Exception
|
||||||
|
*/
|
||||||
|
public function __construct(Zend_Controller_Action $action, $statusCode, $message,
|
||||||
|
$code = 0, Exception $previous = null) {
|
||||||
|
$this->_action = $action;
|
||||||
|
Logging::info("Error in action " . $action->getRequest()->getActionName()
|
||||||
|
. " with status code $statusCode: $message");
|
||||||
|
$action->getResponse()
|
||||||
|
->setHttpResponseCode($statusCode)
|
||||||
|
->appendBody($message);
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAction() {
|
||||||
|
return $this->_action;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -487,32 +487,19 @@ class ApiController extends Zend_Controller_Action
|
||||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$showId = $request->getParam('id');
|
$showId = $request->getParam('id');
|
||||||
|
|
||||||
// If no id is passed, redirect to a 404
|
|
||||||
if (empty($showId)) {
|
if (empty($showId)) {
|
||||||
$this->getResponse()
|
throw new ZendActionHttpException($this, 400, "ERROR: No ID was given.");
|
||||||
->setHttpResponseCode(400)
|
|
||||||
->appendBody("ERROR: No ID was given.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$show = CcShowQuery::create()->findPk($showId);
|
$show = CcShowQuery::create()->findPk($showId);
|
||||||
// Check that a show with this ID exists
|
|
||||||
if (empty($show)) {
|
if (empty($show)) {
|
||||||
$this->getResponse()
|
throw new ZendActionHttpException($this, 400, "ERROR: No show with ID $showId exists.");
|
||||||
->setHttpResponseCode(400)
|
|
||||||
->appendBody("ERROR: No show with ID $showId exists.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $show->getDbImagePath();
|
$path = $show->getDbImagePath();
|
||||||
$mime_type = mime_content_type($path);
|
$mime_type = mime_content_type($path);
|
||||||
|
|
||||||
if (empty($path)) {
|
if (empty($path)) {
|
||||||
$this->getResponse()
|
throw new ZendActionHttpException($this, 400, "ERROR: Show does not have an associated image.");
|
||||||
->setHttpResponseCode(400)
|
|
||||||
->appendBody("ERROR: Show does not have an associated image.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -520,13 +507,9 @@ class ApiController extends Zend_Controller_Action
|
||||||
// but has been cached in a client's browser this will throw an exception
|
// but has been cached in a client's browser this will throw an exception
|
||||||
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type);
|
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type);
|
||||||
} catch(FileNotFoundException $e) {
|
} catch(FileNotFoundException $e) {
|
||||||
$this->getResponse()
|
throw new ZendActionHttpException($this, 404, "ERROR: No image found at $path");
|
||||||
->setHttpResponseCode(404)
|
|
||||||
->appendBody("ERROR: No image found at $path");
|
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->getResponse()
|
throw new ZendActionHttpException($this, 500, "ERROR: " . $e->getMessage());
|
||||||
->setHttpResponseCode(500)
|
|
||||||
->appendBody("ERROR: " . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
|
|
@ -10,7 +10,7 @@ class IndexController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$this->_forward('index', 'showbuilder');
|
$this->_redirect('Showbuilder');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mainAction()
|
public function mainAction()
|
||||||
|
|
Loading…
Reference in New Issue