예제 #1
0
 public function addFailure($index, $key, Exception $e)
 {
     if (isset($this->failed[$index])) {
         throw new Exception("Duplicate index '{$index}' for failure with key '{$key}'");
     }
     $this->failed[$index] = Zotero_Errors::parseException($e);
     $this->failed[$index]['key'] = $key;
     // Log loggable errors as they occur
     if (!empty($this->failed[$index]['log'])) {
         error_log($e);
     }
 }
예제 #2
0
 public function handleException(Exception $e)
 {
     $error = Zotero_Errors::parseException($e);
     if (!empty($error['log'])) {
         $id = substr(md5(uniqid(rand(), true)), 0, 10);
         $str = date("D M j G:i:s T Y") . "  \n";
         $str .= "IP address: " . $_SERVER['REMOTE_ADDR'] . "  \n";
         if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
             $str .= "Version: " . $_SERVER['HTTP_X_ZOTERO_VERSION'] . "  \n";
         }
         $str .= $_SERVER['REQUEST_METHOD'] . " " . $_SERVER['REQUEST_URI'] . "  \n";
         $str .= $error['exception'] . "  \n";
         // Show request body unless it's too big
         if ($error['code'] != 413) {
             $str .= $this->body;
         }
         if (!Z_ENV_TESTING_SITE) {
             file_put_contents(Z_CONFIG::$API_ERROR_PATH . $id, $str);
         }
         error_log($str);
     }
     if ($error['code'] != '500') {
         $errFunc = "e" . $error['code'];
         $this->{$errFunc}($error['message']);
     }
     // On testing site, display unexpected error messages
     if (Z_ENV_TESTING_SITE) {
         $this->e500($str);
     }
     $this->e500();
 }