public function LingotekApi::cancelDocument in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.1.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
- 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocument()
Cancels a document on Lingotek.
Parameters
string $document_id: The document id.
Return value
\Psr\Http\Message\ResponseInterface A response.
Overrides LingotekApiInterface::cancelDocument
File
- src/
Remote/ LingotekApi.php, line 144
Class
- LingotekApi
- A simple connector to the Lingotek Translation API.
Namespace
Drupal\lingotek\RemoteCode
public function cancelDocument($id) {
try {
$this->logger
->debug('Lingotek::cancelDocument called with id %id', [
'%id' => $id,
]);
$args = [
'id' => $id,
'cancelled_reason' => 'CANCELLED_BY_AUTHOR',
];
$response = $this->lingotekClient
->post('/api/document/' . $id . '/cancel', $args);
} catch (ClientException $e) {
if ($e
->getCode() === Response::HTTP_NOT_FOUND) {
$responseBody = json_decode($e
->getResponse()
->getBody(), TRUE);
$message = $responseBody['messages'][0];
throw new LingotekDocumentNotFoundException($message, Response::HTTP_NOT_FOUND);
}
throw new LingotekApiException(new FormattableMarkup('Failed to cancel document: %message', [
'%message' => $e
->getMessage(),
]), $e
->getCode(), $e);
} catch (\Exception $e) {
$this->logger
->error('Error cancelling document: %message.', [
'%message' => $e
->getMessage(),
]);
throw new LingotekApiException(new FormattableMarkup('Failed to cancel document: %message', [
'%message' => $e
->getMessage(),
]), $e
->getCode(), $e);
}
$this->logger
->debug('cancelDocument response received, code %code and body %body', [
'%code' => $response
->getStatusCode(),
'%body' => (string) $response
->getBody(TRUE),
]);
return $response;
}