You are here

private function BaseApiAbstract::processError in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.2 api-sdk-php/src/BaseApiAbstract.php \Smartling\BaseApiAbstract::processError()
  2. 8.2 vendor/smartling/api-sdk-php/src/BaseApiAbstract.php \Smartling\BaseApiAbstract::processError()
  3. 8.3 vendor/smartling/api-sdk-php/src/BaseApiAbstract.php \Smartling\BaseApiAbstract::processError()

Parameters

Response $response:

Throws

SmartlingApiException

2 calls to BaseApiAbstract::processError()
BaseApiAbstract::processErrors in vendor/smartling/api-sdk-php/src/BaseApiAbstract.php
BaseApiAbstract::sendRequest in vendor/smartling/api-sdk-php/src/BaseApiAbstract.php

File

vendor/smartling/api-sdk-php/src/BaseApiAbstract.php, line 390

Class

BaseApiAbstract
Class BaseApiAbstract

Namespace

Smartling

Code

private function processError(Response $response) {
  try {
    $json = json_decode($response
      ->getBody(), true);
    if (is_null($json) || !array_key_exists('response', $json) || !is_array($json['response']) || !array_key_exists('errors', $json['response']) || empty($json['response']['errors'])) {
      $message = 'Bad response format from Smartling';
      $this
        ->getLogger()
        ->error($message);
      throw new SmartlingApiException($message);
    }
    $error_msg = array_map(function ($a) {
      return $a['message'];
    }, $json['response']['errors']);
    $message = implode(' || ', $error_msg);
    $this
      ->getLogger()
      ->error($message);
    throw new SmartlingApiException($json['response']['errors'], $response
      ->getStatusCode());
  } catch (RuntimeException $e) {
    $message = vsprintf('Bad response format from Smartling: %s', [
      $response
        ->getBody(),
    ]);
    $this
      ->getLogger()
      ->error($message);
    throw new SmartlingApiException($message, 0, $e);
  }
}