/** * @param array $data * * @return array|string|null * * @throws \Exception */ public function send($data = null) { $request = new FormRequest($this->method, $this->resource, $this->host); if ($data) { $request->addFields($data); } try { $this->logger->addDebug('Request: ' . $request->getUrl()); /** @var Buzz\Message\Response $response */ $response = $this->client->send($request); $this->logger->addDebug('Response: ' . $response->getStatusCode() . ' ' . substr($response->getContent(), 0, 300) . PHP_EOL . var_export($this->client->getClient()->getInfo(), true)); } catch (\Exception $e) { switch ($e->getCode()) { case 28: $code = 504; break; default: $code = $e->getCode() >= 100 ? $e->getCode() : 500; } $this->logger->addCritical(PHP_EOL . __METHOD__ . sprintf('[%s/%s] %s', $e->getCode(), $code, $e->getMessage())); throw new WebGateException($e->getMessage(), $code, $e); } if ($response->getStatusCode() != 200) { throw new WebGateException(json_decode($response->getContent(), true), $response->getStatusCode()); } return json_decode($response->getContent(), true); }