Skip to content

Commit ed8e8cf

Browse files
committed
TranscodingTask: fix for exception handling
1 parent 68e496d commit ed8e8cf

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Classes/TranscodingTask.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Qencode\Classes;
44

5+
use Qencode\Exceptions\QencodeException;
6+
use Qencode\Exceptions\QencodeApiException;
57
use Qencode\Exceptions\QencodeClientException;
68

79
class TranscodingTask {
@@ -153,6 +155,11 @@ public function startCustom($task_params, $payload = null) {
153155
return $response;
154156
}
155157

158+
private function _retryStatus($params) {
159+
$this->statusUrl = 'https://api.qencode.com/v1/status';
160+
return $this->api->post($this->statusUrl, $params);
161+
}
162+
156163
/**
157164
* Gets current task status from qencode service
158165
* @return array status API method response
@@ -161,14 +168,20 @@ public function getStatus() {
161168
$params = array('task_tokens[]' => $this->taskToken);
162169

163170
try {
164-
$response = $this->api->post($this->statusUrl, $params);
165-
} catch (Exception $e) {
166-
// If the post request fails, fallback to the default URL
167-
$this->statusUrl = 'https://api.qencode.com/v1/status';
168-
$response = $this->api->post($this->statusUrl, $params);
171+
$response = $this->api->post($this->statusUrl.'/test', $params);
172+
}
173+
// If the post request fails, fallback to the default URL
174+
catch(QencodeException $qe) {
175+
$response = $this->_retryStatus($params);
176+
}
177+
catch(Exception $e) {
178+
$response = $this->_retryStatus($params);
179+
}
180+
catch (Throwable $t) {
181+
$response = $this->_retryStatus($params);
169182
}
170183

171-
$this->lastxStatus = $response['statuses'][$this->taskToken];
184+
$this->lastStatus = $response['statuses'][$this->taskToken];
172185
if ($this->lastStatus == null) {
173186
throw new QencodeClientException('Task '. $this->taskToken. ' not found!');
174187
}

0 commit comments

Comments
 (0)