Beispiel #1
0
 /**
  * Exeptions are returned to client in the form
  * of a message in the 'error' element
  * Appropriate http response code is used
  *
  * @param \Exception $e
  */
 protected function handleException(\Exception $e)
 {
     if (!$this->restful) {
         throw $e;
     }
     if ($e instanceof \Lampcms\HttpResponseCodeException) {
         $code = $e->getHttpCode();
         $this->Registry->Response->setHttpCode($code);
         /**
          * @todo if $code = 405 and bRequirePost then
          * set extra header Allow: POST
          * This is to comply with RFC
          */
     } else {
         $this->Registry->Response->setHttpCode(500);
     }
     $err = \strip_tags($e->getMessage());
     $err2 = 'API Exception caught in: ' . $e->getFile() . ' on line: ' . $e->getLine() . ' error: ' . $err;
     d($err2);
     $this->Output->setData(array('error' => $err));
     $this->Registry->Response->setBody($this->Output);
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function handleException(\Exception $e)
 {
     $refl = new \ReflectionClass($e);
     if ($e instanceof HttpExceptionInterface) {
         $title = sprintf('%s::%s', $refl->getShortName(), $e->getErrorType());
         $detail = $e->getMessage();
         $status = $e->getHttpCode();
     } else {
         $title = $refl->getShortName();
         $detail = 'Oh no! Something bad happened on the server! Please try again.';
         $status = 500;
     }
     $serialized = $this->getSerializer()->serializeError($title, $detail, $status);
     $payload = new Rest\RestPayload($serialized);
     return $this->createRestResponse($status, $payload);
 }
Beispiel #3
0
 /**
  * handles an exception when loading a page
  *
  * @param Exception $e
  * @param string $controller name of controller
  * @param string $action name of action
  * @return void
  */
 public function handleException(\Exception $e, $controller = null, $action = null)
 {
     if ($this->_delegate) {
         $this->_delegate->appCaughtException($e, $controller, $action);
     }
     // turn other exceptions into sonic exceptions
     if (!$e instanceof Exception) {
         $e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
     }
     // only set the http code if output hasn't started
     if (!headers_sent()) {
         header($e->getHttpCode());
     }
     $json = false;
     $id = null;
     // in turbo mode we have to write the exception markup out to the
     // same div created before the exception was triggered.  this means
     // we have to get the id based on the controller and action that the
     // exception came from
     if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
         $json = true;
         $id = View::generateId($controller, $action);
     }
     $completed = false;
     // controller and action are only null if this is a page not found
     // because we were not able to match any routes.  in all other cases
     // we can get the initial controller and action to determine if it has
     // completed
     if ($controller !== null && $action !== null) {
         $req = $this->getRequest();
         $first_controller = $req->getControllerName();
         $first_action = $req->getAction();
         $completed = $this->getController($first_controller)->hasCompleted($first_action);
     }
     $args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
     return $this->_runController('main', 'error', $args, $json, $id);
 }
Beispiel #4
0
 public function handleException(\Exception $e, $controller = null, $action = null)
 {
     if ($this->_delegate) {
         $this->_delegate->appCaughtException($e, $controller, $action);
     }
     if (!$e instanceof Exception) {
         $e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
     }
     if (!headers_sent()) {
         header($e->getHttpCode());
     }
     $json = false;
     $id = null;
     if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
         $json = true;
         $id = View::generateId($controller, $action);
     }
     $completed = false;
     if ($controller !== null && $action !== null) {
         $req = $this->getRequest();
         $first_controller = $req->getControllerName();
         $first_action = $req->getAction();
         $completed = $this->getController($first_controller)->hasCompleted($first_action);
     }
     $args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
     return $this->_runController('main', 'error', $args, $json, $id);
 }