Example #1
0
 /**
  * @return Response
  */
 public function handle(Request $request)
 {
     $this->log($request->debug());
     $this->request = $request;
     try {
         $serviceRequest = $this->createServiceRequest($this->request);
         $serviceResponse = $this->route($serviceRequest);
         $this->response = $this->convertResponse($serviceResponse);
     } catch (HTTPResponseException $e) {
         $this->response = Response::create($e->getCode(), $e->getResponseBody(), $e->getHeaders());
     } catch (HTTPException $e) {
         // die darstellung sollte eigentlich woanders sein, nicht hier
         // eigentlich müssten wir hier auch request->content-type auswerten und response umwandeln
         $this->response = Response::create($e->getCode(), sprintf("%s\n\n%s\n%s", $e->getResponseBody(), $request->getResource(), $this->getDebugInfo()), $e->getHeaders());
     } catch (NoServiceFoundException $e) {
         $this->logError($e, $this->debugLevel, 1);
         $e->setCode(404);
         $this->response = Response::create(404, sprintf("Es wurde kein Service für: %s gefunden\n\n%s", $request->getResource(), $this->getDebugInfo()));
     } catch (\Psc\CMS\Service\ControllerRouteException $e) {
         $this->logError($e, $this->debugLevel, 5);
         // nicht 1 da das mit dem Klassennamen ja schon "interna" sind
         $e->setCode(404);
         $this->response = Response::create(404, sprintf($e->getMessage() . "\n\n%s", $this->getDebugInfo()));
     } catch (\Exception $e) {
         $this->logError($e, $this->debugLevel, 1);
         $this->response = Response::create(500, sprintf("Es ist ein Fehler aufgetreten. URL: %s%s\n\n%s", $request->getResource(), $this->debugLevel >= 5 ? "\nFehler: " . $e->getMessage() : NULL, $this->getDebugInfo()), $this->getErrorMessageHeaders($e));
     }
     if (isset($e)) {
         // oder halt code >= 400
         if (!$this->isIgnoredError($e)) {
             $contextInfo = 'im RequestHandler. ' . "\n";
             $contextInfo .= '  ' . $request->getMethod() . ' /' . implode('/', $request->getParts()) . "\n";
             $contextInfo .= '  Accept: ' . $request->getHeaderField('Accept') . "\n";
             $contextInfo .= '  Referer: ' . $request->getReferer() . "\n";
             $contextInfo .= '  User-Agent: ' . $request->getUserAgent();
             if (isset($this->contextInfo)) {
                 $contextInfo .= "\n" . $this->contextInfo;
             }
             $contextInfo .= "\n\n" . $this->dumpRequest($request);
             \Psc\PSC::getEnvironment()->getErrorHandler()->handleCaughtException($e, $contextInfo);
         }
     }
     return $this->response;
 }