Exemplo n.º 1
0
 /**
  * Get the HTTP status code for an API response.
  *
  * @param Omeka\View\Model\ApiJsonModel $response
  * @return int
  */
 protected function getResponseStatusCode(ApiJsonModel $model)
 {
     $response = $model->getApiResponse();
     switch ($response->getStatus()) {
         case Response::SUCCESS:
             if (null === $response->getContent()) {
                 return 204;
                 // No Content
             }
             return 200;
             // OK
         // OK
         case Response::ERROR_VALIDATION:
             return 422;
             // Unprocessable Entity
         // Unprocessable Entity
         case Response::ERROR:
         default:
             return $this->getStatusCodeForException($model->getException());
     }
 }
Exemplo n.º 2
0
 /**
  * Set an error result to the MvcEvent and return the result.
  *
  * @param MvcEvent $event
  * @param Exception $error
  */
 protected function getErrorResult(MvcEvent $event, \Exception $error)
 {
     $response = new Response();
     $response->setStatus(Response::ERROR);
     $result = new ApiJsonModel($response, $this->getViewOptions());
     $result->setException($error);
     $event->setResult($result);
     return $result;
 }