forked from GNUsocial/gnu-social
Use the Action class itself as error handler
This commit is contained in:
parent
2f1bfe126b
commit
6e49281adb
@ -95,9 +95,22 @@ class Action extends HTMLOutputter // lawsuit
|
|||||||
return $this->msg;
|
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) {
|
static public function run(array $args=array(), $output='php://output', $indent=null) {
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
$action = new $class($output, $indent);
|
$action = new $class($output, $indent);
|
||||||
|
set_exception_handler(array($action, 'handleError'));
|
||||||
$action->execute($args);
|
$action->execute($args);
|
||||||
return $action;
|
return $action;
|
||||||
}
|
}
|
||||||
@ -1443,7 +1456,7 @@ class Action extends HTMLOutputter // lawsuit
|
|||||||
$this->endDocument('json');
|
$this->endDocument('json');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ServerException($msg, $code);
|
common_log(LOG_ERR, 'Handled '.get_class($e).' but cannot output into desired format: '._ve($e->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
exit((int)$code);
|
exit((int)$code);
|
||||||
@ -1471,7 +1484,7 @@ class Action extends HTMLOutputter // lawsuit
|
|||||||
if (!array_key_exists($code, ClientErrorAction::$status)) {
|
if (!array_key_exists($code, ClientErrorAction::$status)) {
|
||||||
$code = 400;
|
$code = 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
$status_string = ClientErrorAction::$status[$code];
|
$status_string = ClientErrorAction::$status[$code];
|
||||||
|
|
||||||
switch ($format) {
|
switch ($format) {
|
||||||
@ -1499,7 +1512,7 @@ class Action extends HTMLOutputter // lawsuit
|
|||||||
echo $msg;
|
echo $msg;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ClientException($msg, $code);
|
common_log(LOG_ERR, 'Handled '.get_class($e).' but cannot output into desired format: '._ve($e->getMessage()));
|
||||||
}
|
}
|
||||||
exit((int)$code);
|
exit((int)$code);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user