throw $e;
}
else {
- throw new AJAXException($e);
+ $this->throwException($e);
}
}
}
$this->objectAction->validateAction();
}
catch (ValidateActionException $e) {
- throw new SystemException("validation failed: ".$e->getMessage());
+ $this->throwException($e);
}
// execute action
$this->response = $this->objectAction->executeAction();
}
catch (\Exception $e) {
- throw new SystemException('unknown exception caught: '.$e->getMessage());
+ $this->throwException($e);
}
$this->executed();
echo JSON::encode($this->response);
exit;
}
+
+ /**
+ * Throws an previously catched exception while maintaing the propriate stacktrace.
+ *
+ * @param \Exception $e
+ */
+ protected function throwException(\Exception $e) {
+ if ($e instanceof SystemException) {
+ throw new AJAXException($e->getMessage(), $e->__getTraceAsString());
+ }
+ else {
+ throw new AJAXException($e->getMessage(), $e->getTraceAsString());
+ }
+ }
}
/**
* Throws a JSON-encoded error message
*
- * @param \Exception $exception
+ * @param string $message
+ * @param string $stacktrace
*/
- public function __construct(\Exception $exception) {
- $stacktrace = $exception->getTraceAsString();
- if ($exception instanceof SystemException) {
- $stacktrace = $exception->__getTraceAsString();
- }
+ public function __construct($message, $stacktrace = null) {
+ if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
//header('HTTP/1.0 418 I\'m a Teapot');
header('HTTP/1.0 503 Service Unavailable');
header('Content-type: application/json');
echo JSON::encode(array(
- 'message' => $exception->getMessage(),
+ 'message' => $message,
'stacktrace' => nl2br($stacktrace)
));
exit;