Skip to content

Commit 0c5854b

Browse files
committed
moved request method in Client
1 parent f280df7 commit 0c5854b

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/Client.php

+38-38
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,44 @@ public function __construct(
3838
);
3939
}
4040

41+
/**
42+
* @throws BlobAccessException
43+
* @throws BlobException
44+
* @throws BlobNotFoundException
45+
* @throws BlobServiceNotAvailableException
46+
* @throws BlobServiceRateLimitedException
47+
* @throws BlobStoreNotFoundException
48+
* @throws BlobStoreSuspendedException
49+
* @throws BlobUnknownException
50+
* @throws GuzzleException
51+
* @throws JsonException
52+
*/
53+
public function request(string $uri, string $method, array $options = []): ResponseInterface
54+
{
55+
try {
56+
$response = $this->client->request($method, $uri, $options);
57+
} catch (ClientException $exception) {
58+
$response = $exception->getResponse();
59+
$body = json_decode($response->getBody(), true, flags: JSON_THROW_ON_ERROR);
60+
61+
$code = $body['error']['code'] ?? 'unknown_error';
62+
$message = $body['error']['message'] ?? null;
63+
64+
throw match ($code) {
65+
'store_suspended' => new BlobStoreSuspendedException(),
66+
'forbidden' => new BlobAccessException(),
67+
'not_found' => new BlobNotFoundException(),
68+
'store_not_found' => new BlobStoreNotFoundException(),
69+
'bad_request' => new BlobException($message ?? 'Bad request'),
70+
'service_unavailable' => new BlobServiceNotAvailableException(),
71+
'rate_limited' => new BlobServiceRateLimitedException((int)$response->getHeaderLine('retry-after')),
72+
default => new BlobUnknownException(),
73+
};
74+
}
75+
76+
return $response;
77+
}
78+
4179
/**
4280
* @return PutBlobResult
4381
* @throws BlobAccessException
@@ -283,44 +321,6 @@ private function getApiToken(): string
283321
return getenv("BLOB_READ_WRITE_TOKEN") ?: '';
284322
}
285323

286-
/**
287-
* @throws BlobAccessException
288-
* @throws BlobException
289-
* @throws BlobNotFoundException
290-
* @throws BlobServiceNotAvailableException
291-
* @throws BlobServiceRateLimitedException
292-
* @throws BlobStoreNotFoundException
293-
* @throws BlobStoreSuspendedException
294-
* @throws BlobUnknownException
295-
* @throws GuzzleException
296-
* @throws JsonException
297-
*/
298-
private function request(string $uri, string $method, array $options = []): ResponseInterface
299-
{
300-
try {
301-
$response = $this->client->request($method, $uri, $options);
302-
} catch (ClientException $exception) {
303-
$response = $exception->getResponse();
304-
$body = json_decode($response->getBody(), true, flags: JSON_THROW_ON_ERROR);
305-
306-
$code = $body['error']['code'] ?? 'unknown_error';
307-
$message = $body['error']['message'] ?? null;
308-
309-
throw match ($code) {
310-
'store_suspended' => new BlobStoreSuspendedException(),
311-
'forbidden' => new BlobAccessException(),
312-
'not_found' => new BlobNotFoundException(),
313-
'store_not_found' => new BlobStoreNotFoundException(),
314-
'bad_request' => new BlobException($message ?? 'Bad request'),
315-
'service_unavailable' => new BlobServiceNotAvailableException(),
316-
'rate_limited' => new BlobServiceRateLimitedException((int)$response->getHeaderLine('retry-after')),
317-
default => new BlobUnknownException(),
318-
};
319-
}
320-
321-
return $response;
322-
}
323-
324324
/**
325325
* @throws JsonException
326326
*/

0 commit comments

Comments
 (0)