You are here

protected function Nodejs::httpRequest in Node.js integration 8

13 calls to Nodejs::httpRequest()
Nodejs::addChannel in src/Nodejs.php
Nodejs::addUserToChannel in src/Nodejs.php
Nodejs::checkChannel in src/Nodejs.php
Nodejs::getContentTokenUsers in src/Nodejs.php
Nodejs::healthCheck in src/Nodejs.php

... See full list

File

src/Nodejs.php, line 185

Class

Nodejs

Namespace

Drupal\nodejs

Code

protected function httpRequest($path, array $options = []) {

  // Only send messages if the site is not in maintenance mode.
  if ($this->state
    ->get('system.maintenance_mode')) {
    return FALSE;
  }
  $options += [
    'method' => 'GET',
    'timeout' => !empty($this->config['timeout']) ? $this->config['timeout'] : 5,
    'headers' => [],
  ];
  $options['headers'] += [
    'NodejsServiceKey' => $this->config['service_key'],
    'Content-type' => 'application/json',
  ];
  try {
    $response = $this->httpClient
      ->request($options['method'], $this
      ->getUrl($path), $options);
    if ($response
      ->getStatusCode() != 200) {
      return FALSE;
    }
    return (object) Json::decode($response
      ->getBody(TRUE));
  } catch (BadResponseException $e) {
    $this->logger
      ->error($e
      ->getMessage() . "\n" . $e
      ->getTraceAsString());
  } catch (RequestException $e) {
    $this->logger
      ->error($e
      ->getMessage() . "\n" . $e
      ->getTraceAsString());
  } catch (\Exception $e) {
    $this->logger
      ->error($e
      ->getMessage() . "\n" . $e
      ->getTraceAsString());
  }
  return FALSE;
}