Exemple #1
0
 /**
  * Renders an error template for PHP errors and Exceptions
  */
 public function _onException($e)
 {
     $response = new Response();
     $error = $this->_filterError($e);
     $data = ["status" => $this->_status, "title" => $this->_status . ": " . $error["type"], "description" => "There has been a problem of type (" . $error["type"] . ").", "address" => Server::getUrl(), "method" => Connection::getMethod(), "date" => date("F jS Y h:i:s A T"), "headers" => getallheaders(), "error" => $error];
     // send error data to log file
     $this->log($error["type"] . ": " . $error["message"] . " in " . $error["file"] . " on line " . $error["line"] . ".");
     // send http reposnse
     if (Connection::isMethod("GET")) {
         // template has been set...
         if (!empty($this->_template) && is_file($this->_template)) {
             // send all data to template to be rendered as needed
             $response->sendTemplate($this->_status, $this->_template, $data);
         }
         // no template, send just error description for security reasons
         $response->sendText($this->_status, $data["description"]);
     }
     // non-GET, send error description data as JSON
     $response->sendJson($this->_status, ["status" => $this->_status, "error" => $data["description"]]);
 }
Exemple #2
0
 /**
  * Renders a JSON encoded error response
  */
 private function _renderJson()
 {
     $data = $this->_getOutputData(false);
     $data = $this->filterEvent('renderJson', $data);
     $response = new Response();
     $response->setJson($this->_status_code, $data);
     $response->send();
     exit;
 }