Example #1
0
 /**
  * Handles react request and create http compliant request/response objects
  *
  * @param ReactRequestEvent $event
  */
 public function onRequest(ReactRequestEvent $event)
 {
     $event->stopPropagation();
     $request = RequestFactory::createFromReact($event->getRequest(), $event->getData());
     $response = new Response();
     $response->setReactResponse($event->getResponse());
     try {
         $this->dispatcher->trigger($requestEvent = new HttpRequestEvent($request, $response));
         if ($requestEvent->shouldPropagate()) {
             $response->setStatusCode(new StatusCode(StatusCode::NOT_FOUND))->setContent("");
         }
     } catch (AbstractHttpException $e) {
         $this->dispatcher->trigger($exceptionEvent = new HttpExceptionEvent($e, $request, $response));
         if ($exceptionEvent->shouldPropagate()) {
             $response->setStatusCode($e->getStatusCode());
             if (trim($e->getMessage()) != '') {
                 $response->setContent($e->getMessage());
             } else {
                 $response->getHeaders()->remove('Content-Type');
                 $response->setContent("");
             }
         }
     } catch (\Exception $e) {
         $this->dispatcher->trigger($event = new UnknownHttpExceptionEvent($e, $request, $response));
         if ($event->shouldPropagate()) {
             $response->setStatusCode(new StatusCode(StatusCode::INTERNAL_SERVER_ERROR));
             $response->getHeaders()->remove('Content-Type');
             $response->setContent("");
         }
     }
 }
Example #2
0
 /**
  * Handle http exceptions
  *
  * @param UnknownHttpExceptionEvent $event
  */
 public function onException(UnknownHttpExceptionEvent $event)
 {
     if (!$this->environment->equals(Environment::DEVELOPMENT)) {
         return;
     }
     $event->stopPropagation();
     $this->whoops->writeToOutput(false);
     $this->whoops->allowQuit(false);
     $content = $this->whoops->handleException($event->getHttpException());
     $event->getResponse()->setContent($content);
 }