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); }