Example #1
0
 protected function useResponse(Request $request, Response $response, $filter = null)
 {
     if ($request->isExpectingResult()) {
         $this->serializer->expects($this->once())->method($response->getType() === MessageTypes::ERROR ? 'serializeError' : 'serializeResult')->with($request->getMethodName(), $this->equalTo($response->getResultBody(), 0, 0), $response->getHeaders()->get('content-type'))->will($this->returnValue($response->getResultBody()));
     } else {
         $this->serializer->expects($this->never())->method('serializeResult');
     }
     if (!$filter) {
         $filter = function () {
         };
     }
     $this->transport->expects($this->once())->method('sendResponse')->with($response)->will($this->returnCallback($filter));
 }
 /**
  * {@inheritDoc}
  */
 public function sendResponse(Response $response)
 {
     $message = array($response->getType(), (string) $response->getHeaders());
     if (MessageTypes::isResponseTypeWithResult($response->getType())) {
         $message[2] = $response->getResultBody();
     }
     try {
         $this->socket->sendMulti($message);
         $this->waitingForResponse = false;
     } catch (\Exception $e) {
         $this->waitingForResponse = false;
         throw new TransportException('Unable to send request', null, $e);
     }
 }
Example #3
0
 private function handleError(Response $response, Request $request)
 {
     $responseData = $this->serializer->unserializeError($request->getMethodName(), $response->getResultBody(), $response->getHeaders()->get('Content-Type'));
     if ($responseData instanceof \Exception) {
         $this->replaceExceptionTrace($responseData);
         throw $responseData;
     }
     if ($request->getType() === MessageTypes::PING) {
         $msg = 'Error caught during ping';
     } else {
         $msg = 'Error caught during execution of method "' . $request->getMethodName() . '"';
     }
     throw new ErrorResponseException($msg, $responseData);
 }