Example #1
0
 /**
  * API PHP Exception handler.
  * This is a generic exception handler for PHP exceptions. This will catch any
  * uncaught exception, end API execution and return the result to the requestor
  * as an ErrorResult in the requested format.
  *
  * @param Exception $exception Exception
  *
  * @return void
  * @access private
  */
 public function exceptionHandler($exception)
 {
     $time = date("Y-m-d H:i:s (T)");
     $msg = $exception->getMessage() ?: elgg_echo('Exception:UnknownType');
     $code = $exception->getCode() ?: 500;
     $error = "{$time}: {$msg} in file {$exception->getFile()} (line {$exception->getLine()})";
     $this->log($error, "EXCEPTION");
     $result = new ErrorResult($msg, $code, $exception);
     if ($this->router) {
         $this->router->send($result);
     } else {
         $output = elgg_view('graph/output', array('result' => $result));
         if (elgg_get_viewtype() === 'default') {
             $layout = elgg_view_layout('one_column', array('content' => $output));
             $output = elgg_view_page('', $layout);
         }
         HttpResponse::create($output, $result->getStatusCode())->send();
     }
 }