Example #1
0
 /**
  * @throws ServiceException
  *
  * solve exception depending from enter message (number or string)
  * if message is numeric get code from Response class and redirect to 500 html page
  * if string redirect to $redirectAddress
  */
 public function solveException()
 {
     $data = array();
     if ($this->getMessage() && is_numeric($this->getMessage())) {
         $data['code'] = $this->getMessage();
         $data['message'] = Response::getMessageByCode($this->getMessage());
         if ($this->beforeSolve) {
             $this->beforeSolveException();
         }
         $renderer = new Renderer();
         $responce = new Response($renderer::render(Service::get('config')->get500Layout(), $data), 'text/html', 202);
         $responce->send();
     } else {
         if ($this->getMessage()) {
             Service::get('session')->addFlush($this->type, $this->getMessage());
             if ($this->beforeSolve) {
                 $this->beforeSolveException();
             }
             echo $this->redirectAddress;
             $redirect = new ResponseRedirect($this->redirectAddress);
             $redirect->sendHeaders();
         } else {
             throw new ServiceException(500);
         }
     }
 }