Drest\Service::handleError PHP Method

handleError() public method

Handle an error - set the resulting error document to the response object
public handleError ( Exception $e, integer $defaultResponseCode = 500, DrestCommon\Error\Response\ResponseInterface $errorDocument = null ) : DrestCommon\ResultSet
$e Exception
$defaultResponseCode integer the default response code to use if no match on exception type occurs
$errorDocument DrestCommon\Error\Response\ResponseInterface
return DrestCommon\ResultSet the error result set
    public function handleError(\Exception $e, $defaultResponseCode = 500, ResponseInterface $errorDocument = null)
    {
        if (is_null($errorDocument)) {
            $errorDocument = $this->representation->getDefaultErrorResponse();
        }
        $this->error_handler->error($e, $defaultResponseCode, $errorDocument);
        $this->getResponse()->setStatusCode($this->error_handler->getResponseCode());
        $this->getResponse()->setHttpHeader('Content-Type', $errorDocument::getContentType());
        $this->getResponse()->setBody($errorDocument->render());
    }

Usage Example

Esempio n. 1
0
 /**
  * Handle an error - set the resulting error document to the response object
  * @param  \Exception        $e
  * @param  integer           $defaultResponseCode the default response code to use if no match on exception type occurs
  * @param  ResponseInterface $errorDocument
  * @return ResultSet         the error result set
  */
 public function handleError(\Exception $e, $defaultResponseCode = 500, ResponseInterface $errorDocument = null)
 {
     return $this->service->handleError($e, $defaultResponseCode, $errorDocument);
 }