Skip to content

Commit

Permalink
fix(client): Handle Guzzle ClientException (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it authored and ankitpokhrel committed Nov 27, 2020
1 parent 126a185 commit 0c548f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Tus/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,13 @@ public function create(string $key) : string
$headers += ['Upload-Concat' => 'partial'];
}

$response = $this->getClient()->post($this->apiPath, [
'headers' => $headers,
]);
try {
$response = $this->getClient()->post($this->apiPath, [
'headers' => $headers,
]);
} catch (ClientException $e) {
$response = $e->getResponse();
}

$statusCode = $response->getStatusCode();

Expand Down
8 changes: 7 additions & 1 deletion tests/Tus/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ public function it_throws_exception_when_unable_to_create_resource() : void

$this->tusClientMock->file($filePath, $fileName);

$clientExceptionMock = m::mock(ClientException::class);
$clientExceptionMock
->shouldReceive('getResponse')
->once()
->andReturn($responseMock);

$guzzleMock
->shouldReceive('post')
->once()
Expand All @@ -1378,7 +1384,7 @@ public function it_throws_exception_when_unable_to_create_resource() : void
'Upload-Metadata' => 'filename ' . base64_encode($fileName),
],
])
->andReturn($responseMock);
->andThrow($clientExceptionMock);

$this->tusClientMock->create($key);
}
Expand Down

0 comments on commit 0c548f0

Please sign in to comment.