diff --git a/include/class.error.php b/include/class.error.php index ed5bf7e4c3d8d0384c63f0d8a4dbaa7af8b543a3..602304f763c5166b75b854c43597a893f6d42220 100644 --- a/include/class.error.php +++ b/include/class.error.php @@ -17,39 +17,32 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ -class Error /* extends Exception */ { - var $title = ''; +class Error extends Exception { + static $title = ''; + static $sendAlert = true; - function Error($message) { - call_user_func_array(array($this,'__construct'), func_get_args()); - } function __construct($message) { global $ost; $message = str_replace(ROOT_DIR, '(root)/', $message); if ($ost->getConfig()->getLogLevel() == 3) - $message .= "\n\n" . $this->formatBacktrace(debug_backtrace()); + $message .= "\n\n" . $this->getBacktrace(); - $ost->logError($this->getTitle(), $message); + $ost->logError($this->getTitle(), $message, static::$sendAlert); } function getTitle() { - return get_class($this) . ": {$this->title}"; + return get_class($this) . ': ' . static::$title; } - function formatBacktrace($bt) { - $buffer = array(); - foreach ($bt as $i=>$frame) - $buffer[] = sprintf("#%d %s%s%s at [%s:%d]", $i, - $frame['class'], $frame['type'], $frame['function'], - str_replace(ROOT_DIR, '', $frame['file']), $frame['line']); - return implode("\n", $buffer); + function getBacktrace() { + return str_replace(ROOT_DIR, '(root)/', $this->getTraceAsString()); } } class InitialDataError extends Error { - var $title = 'Problem with install initial data'; + static $title = 'Problem with install initial data'; } function raise_error($message, $class=false) { @@ -57,4 +50,9 @@ function raise_error($message, $class=false) { new $class($message); } +// File storage backend exceptions +class IOException extends Error { + static $title = 'Unable to read resource content'; +} + ?> diff --git a/include/class.file.php b/include/class.file.php index 4972bbb1e6df46ce59f58078ebd78b3aa0139cd8..a5cc07940e67f7e62bfcfcd8acc9bc9cdf5f133c 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -12,6 +12,7 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ require_once(INCLUDE_DIR.'class.signal.php'); +require_once(INCLUDE_DIR.'class.error.php'); class AttachmentFile { @@ -118,14 +119,24 @@ class AttachmentFile { return; @ini_set('zlib.output_compression', 'Off'); - $bk->passthru(); + try { + $bk->passthru(); + } + catch (IOException $ex) { + Http::response(404, 'File not found'); + } } function getData() { # XXX: This is horrible, and is subject to php's memory # restrictions, etc. Don't use this function! ob_start(); - $this->sendData(false); + try { + $this->sendData(false); + } + catch (IOException $ex) { + Http::response(404, 'File not found'); + } $data = &ob_get_contents(); ob_end_clean(); return $data;