Imbo\Http\Response\Response::setError PHP Method

setError() public method

Set an error model and update some parts of the response object
public setError ( Error $error ) : Response
$error Imbo\Model\Error An error model instance
return Response
    public function setError(Model\Error $error)
    {
        $errorMessage = $error->getErrorMessage();
        $this->headers->add(['X-Imbo-Error-Message' => $errorMessage, 'X-Imbo-Error-InternalCode' => $error->getImboErrorCode(), 'X-Imbo-Error-Date' => $error->getDate()->format('D, d M Y H:i:s') . ' GMT']);
        $this->setStatusCode($error->getHttpCode(), $errorMessage)->setEtag(null)->setLastModified(null);
        $this->setModel($error);
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @covers Imbo\Http\Response\Response::setError
  */
 public function testUpdatesResponseWhenSettingAnErrorModel()
 {
     $message = 'You wronged';
     $code = 404;
     $imboErrorCode = 123;
     $date = new DateTime('@1361614522', new DateTimeZone('UTC'));
     $error = $this->getMock('Imbo\\Model\\Error');
     $error->expects($this->once())->method('getHttpCode')->will($this->returnValue($code));
     $error->expects($this->once())->method('getImboErrorCode')->will($this->returnValue($imboErrorCode));
     $error->expects($this->once())->method('getErrorMessage')->will($this->returnValue($message));
     $error->expects($this->once())->method('getDate')->will($this->returnValue($date));
     $this->response->headers->set('ETag', '"sometag"');
     $this->response->setLastModified(new DateTime('now', new DateTimeZone('UTC')));
     $this->response->setError($error);
     $this->assertSame($code, $this->response->getStatusCode());
     $this->assertSame($message, $this->response->headers->get('X-Imbo-Error-Message'));
     $this->assertSame($imboErrorCode, $this->response->headers->get('X-Imbo-Error-InternalCode'));
     $this->assertNull($this->response->headers->get('ETag'));
     $this->assertNull($this->response->getLastModified());
 }
All Usage Examples Of Imbo\Http\Response\Response::setError