You are here

public function LingotekApi::getProcess in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getProcess()
  2. 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getProcess()

Gets the status of a process.

Parameters

string $process_id: The process id.

Return value

\Psr\Http\Message\ResponseInterface A response.

Overrides LingotekApiInterface::getProcess

File

src/Remote/LingotekApi.php, line 543

Class

LingotekApi
A simple connector to the Lingotek Translation API.

Namespace

Drupal\lingotek\Remote

Code

public function getProcess($process_id) {
  try {
    $this->logger
      ->debug('Lingotek::getProcess called with id %id', [
      '%id' => $process_id,
    ]);
    $response = $this->lingotekClient
      ->get('/api/process/' . $process_id);
  } catch (ClientException $e) {
    if ($e
      ->getCode() === Response::HTTP_NOT_FOUND) {
      $responseBody = json_decode($e
        ->getResponse()
        ->getBody(), TRUE);
      $message = $responseBody['messages'][0];
      throw new LingotekApiException($message, Response::HTTP_NOT_FOUND);
    }
    throw new LingotekApiException('Failed to get process info: ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  } catch (\Exception $e) {
    $this->logger
      ->error('Error getting process info (%id): %message.', [
      '%id' => $process_id,
      '%message' => $e
        ->getMessage(),
    ]);
    throw new LingotekApiException('Failed to get process info: ' . $e
      ->getMessage());
  }
  $this->logger
    ->debug('getProcess response received, code %code and body %body', [
    '%code' => $response
      ->getStatusCode(),
    '%body' => (string) $response
      ->getBody(TRUE),
  ]);
  return $response;
}