Beispiel #1
0
 public function setContent($data, $convert = true)
 {
     if ($convert) {
         $this->data = $data;
         $data = XML::encode($data);
     }
     parent::setContent($data);
 }
Beispiel #2
0
 public static function handle($e, $send_response = true)
 {
     try {
         Hook::triggerAction('exception.handle', array(&$e));
         $log_message = sprintf('%-4s %s', "({$e->getCode()})", $e->getMessage());
         // get the channel manually so the introspection works properly.
         $level = Log::ERROR;
         if ($e instanceof ErrorException && isset(self::$levels[$e->getSeverity()])) {
             $level = self::$levels[$e->getSeverity()];
         }
         Log::getChannel('exception')->addRecord($level, $log_message, array('exception' => $e));
         $request = static::$request;
         if ($request === null) {
             $request = Request::createFromGlobals();
         }
         $action = Action::getDefaultAction(self::$_controller);
         $action->setRespondsWith(array('*'), false);
         $response = Controller::invoke($action, $request, array('exception' => $e));
         $response->prepare($request);
         if ($send_response) {
             $response->send();
         }
         return $response;
     } catch (\Exception $_e) {
         $response = new Response();
         $response->setStatusCode(500);
         if (Core::$_MODE === Core::MODE_PRODUCTION) {
             $response->setContent("Internal server error");
         } else {
             $response->setContent($e->__toString() . "\n\n\nAdditionally, the following exception occurred while trying to handle the error:\n\n" . $_e->__toString());
         }
         return $response;
     }
 }