X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Faction.php;h=4e629c2bc34d0b6c3fb730670d53bdbafc6ebe69;hb=543d968b81b97c9ebd46de063d8d70621c12015b;hp=c2d60e11e974bec1414fe2b9b143b4babdb4ce0d;hpb=0f938ff23479d92113620552eab76b50613c87e3;p=quix0rs-gnu-social.git diff --git a/lib/action.php b/lib/action.php index c2d60e11e9..4e629c2bc3 100644 --- a/lib/action.php +++ b/lib/action.php @@ -95,9 +95,22 @@ class Action extends HTMLOutputter // lawsuit return $this->msg; } + public function handleError($e) + { + if ($e instanceof ClientException) { + $this->clientError($e->getMessage(), $e->getCode()); + } elseif ($e instanceof ServerException) { + $this->serverError($e->getMessage(), $e->getCode()); + } else { + // If it wasn't specified more closely which kind of exception it was + $this->serverError($e->getMessage(), 500); + } + } + static public function run(array $args=array(), $output='php://output', $indent=null) { $class = get_called_class(); $action = new $class($output, $indent); + set_exception_handler(array($action, 'handleError')); $action->execute($args); return $action; } @@ -416,7 +429,6 @@ class Action extends HTMLOutputter // lawsuit $this->script('extlib/jquery.form.js'); $this->script('extlib/jquery-ui/jquery-ui.js'); $this->script('extlib/jquery.cookie.js'); - $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.js', GNUsocial::isHTTPS()).'"); }'); Event::handle('EndShowJQueryScripts', array($this)); } @@ -1154,7 +1166,7 @@ class Action extends HTMLOutputter // lawsuit $url = $sslimage; } else if (preg_match('#^http://i.creativecommons.org/#', $image)) { // CC support HTTPS on their images - $url = preg_replace('/^http/', 'https', $image); + $url = preg_replace('/^http/', 'https', $image, 1); } else { // Better to show mixed content than no content $url = $image; @@ -1443,7 +1455,9 @@ class Action extends HTMLOutputter // lawsuit $this->endDocument('json'); break; default: - throw new ServerException($msg, $code); + common_log(LOG_ERR, 'Handled serverError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg)); + $action = new ServerErrorAction($msg, $code); + $action->execute(); } exit((int)$code); @@ -1471,7 +1485,7 @@ class Action extends HTMLOutputter // lawsuit if (!array_key_exists($code, ClientErrorAction::$status)) { $code = 400; } - + $status_string = ClientErrorAction::$status[$code]; switch ($format) { @@ -1499,7 +1513,9 @@ class Action extends HTMLOutputter // lawsuit echo $msg; break; default: - throw new ClientException($msg, $code); + common_log(LOG_ERR, 'Handled clientError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg)); + $action = new ClientErrorAction($msg, $code); + $action->execute(); } exit((int)$code); }