Skip to content

Commit

Permalink
Properly parse file query errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Mar 4, 2024
1 parent 5a1aff0 commit 874857e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/Repositories/Proxmox/Node/ProxmoxStorageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Convoy\Data\Node\Storage\FileMetaData;
use Convoy\Data\Node\Storage\IsoData;
use Convoy\Enums\Node\Storage\ContentType;
use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException;
use Convoy\Exceptions\Service\Node\IsoLibrary\InvalidIsoLinkException;
use Convoy\Models\Node;
use Convoy\Repositories\Proxmox\ProxmoxRepository;
Expand Down Expand Up @@ -96,15 +97,21 @@ public function getFileMetadata(string $link, bool $verifyCertificates = true):
Assert::isInstanceOf($this->node, Node::class);
Assert::regex($link, '/^(http|https):\/\//');

$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
])
->get('/api2/json/nodes/{node}/query-url-metadata', [
'url' => $link,
'verify-certificates' => $verifyCertificates,
])
->json();
try {
$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
])
->get('/api2/json/nodes/{node}/query-url-metadata', [
'url' => $link,
'verify-certificates' => $verifyCertificates,
])
->json();
} catch (ProxmoxConnectionException $e) {
if (str_contains($e->getMessage(), "Can't connect to")) {
throw new InvalidIsoLinkException();
}
}

if (Arr::get($response, 'success', 1) !== 1) {
throw new InvalidIsoLinkException();
Expand Down

0 comments on commit 874857e

Please sign in to comment.