Skip to content

Commit ff92aa1

Browse files
committed
Merge branch 'develop'
2 parents a721274 + d8447be commit ff92aa1

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 9.3.0 - 2025-08-18
4+
5+
When the Assets sessions expires in AssetsClient::downloadFileToPath(), re-authenticate instead of
6+
throwing an exception.
7+
38
## 9.2.0 - 2025-08-13
49

510
Update to PHPUnit 12 and php-timer 8.

src/AssetsClient.php

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,16 @@ public function serviceRequest(
238238
return $this->serviceRequest($method, $service, $data, $multipart);
239239
default:
240240
// something went wrong
241-
$this->logger->error(sprintf(
242-
'%s: %s request to <%s> failed: <%d> "%s"',
243-
__METHOD__,
244-
$method,
245-
$url,
246-
$e->getCode(),
247-
$e->getMessage()
248-
));
241+
$this->logger->error(
242+
sprintf(
243+
'%s: %s request to <%s> failed: <%d> "%s"',
244+
__METHOD__,
245+
$method,
246+
$url,
247+
$e->getCode(),
248+
$e->getMessage()
249+
)
250+
);
249251
throw $e;
250252
}
251253
}
@@ -293,14 +295,16 @@ public function apiRequest(string $method, string $urlPath, array $data = []): a
293295
return $this->apiRequest($method, $urlPath, $data);
294296
default:
295297
// something went wrong
296-
$this->logger->error(sprintf(
297-
'%s: %s request to <%s> failed: <%d> "%s"',
298-
__METHOD__,
299-
$method,
300-
$url,
301-
$e->getCode(),
302-
$e->getMessage()
303-
));
298+
$this->logger->error(
299+
sprintf(
300+
'%s: %s request to <%s> failed: <%d> "%s"',
301+
__METHOD__,
302+
$method,
303+
$url,
304+
$e->getCode(),
305+
$e->getMessage()
306+
)
307+
);
304308
throw $e;
305309
}
306310
}
@@ -625,7 +629,36 @@ public function logout(bool $cleanUpToken = true): LogoutResponse
625629
*/
626630
public function downloadFileToPath(string $url, string $targetPath): void
627631
{
628-
$httpResponse = $this->request('GET', $url, ['forceDownload' => 'true'], false);
632+
try {
633+
$httpResponse = $this->request('GET', $url, ['forceDownload' => 'true'], false);
634+
} catch (GuzzleException $e) {
635+
switch ($e->getCode()) {
636+
case 401: // Unauthorized
637+
// TODO: prevent a possible loop here?
638+
639+
// re-login
640+
if (!$this->reLogin()) {
641+
throw $e;
642+
}
643+
644+
// try again
645+
$this->downloadFileToPath($url, $targetPath);
646+
return;
647+
default:
648+
// something went wrong
649+
$this->logger->error(
650+
sprintf(
651+
'%s: GET request to <%s> failed: <%d> "%s"',
652+
__METHOD__,
653+
$url,
654+
$e->getCode(),
655+
$e->getMessage()
656+
)
657+
);
658+
throw $e;
659+
}
660+
}
661+
629662
$this->writeResponseBodyToPath($httpResponse, $targetPath);
630663
}
631664

0 commit comments

Comments
 (0)