Exemplo n.º 1
0
 /**
  * Throws an ValidationResponse
  *
  * it handles the JSON case and the HTML case
  * @param ValidatorException[]
  * @param const $format im moment nur JSON oder HTML
  * @return HTTPException
  */
 public function validationResponse(\Psc\Form\ValidatorExceptionList $list, $format = ServiceResponse::JSON, MetadataGenerator $metadataGenerator = NULL)
 {
     if ($format === ServiceResponse::JSON) {
         $body = (object) array('errors' => array());
         foreach ($list->getExceptions() as $validatorException) {
             $body->errors[$validatorException->field] = $validatorException->getMessage();
         }
         return HTTPResponseException::BadRequest(json_encode($body), NULL, array('Content-Type' => 'application/json'));
     } else {
         $metadataGenerator = $metadataGenerator ?: new MetadataGenerator();
         return HTTPException::BadRequest($list->getMessage(), $list, array_merge(array('Content-Type' => 'text/html'), $metadataGenerator->validationList($list)->toHeaders()));
     }
 }
Exemplo n.º 2
0
 /**
  * @return ServiceResponse
  */
 public function route(ServiceRequest $serviceRequest)
 {
     try {
         $this->service = $this->findService($serviceRequest);
         return $this->service->route($serviceRequest);
     } catch (\Psc\Form\ValidatorException $e) {
         $this->logError($e, $this->debugLevel, 2);
         throw HTTPException::BadRequest(sprintf("Beim Validieren der Daten ist ein Fehler aufgetreten. %s", $e->getMessage()), $e, array_merge(array('Content-Type' => 'text/html'), $this->metadataGenerator->validationError($e)->toHeaders()));
     } catch (\Psc\Form\ValidatorExceptionList $list) {
         $this->logError($list, $this->debugLevel, 2);
         throw $this->err->validationResponse($list, $this->request->accepts('application/json') ? ServiceResponse::JSON : ServiceResponse::HTML, $this->metadataGenerator);
     }
 }
Exemplo n.º 3
0
 public static function provideServiceExceptions()
 {
     return array(array(\Psc\Net\HTTP\HTTPException::NotFound()), array(\Psc\Net\HTTP\HTTPException::BadRequest()), array(new \Exception('Manno')), array(new \Psc\Exception('I am faling')));
 }