forked from cwhite92/b2-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor, improve exception handling, tests
- Loading branch information
Showing
54 changed files
with
596 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class AccessDeniedException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
use GuzzleHttp\Exception\RequestException; | ||
use JsonException; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Throwable; | ||
|
||
class B2APIException extends RequestException { | ||
|
||
private $statusCode; | ||
|
||
public function __construct( | ||
RequestInterface $request, | ||
ResponseInterface $response, | ||
?Throwable $previous = null | ||
) { | ||
$message = $response->getReasonPhrase(); | ||
$code = $response->getStatusCode(); | ||
|
||
try { | ||
$responseJson = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$this->statusCode = $responseJson['status'] ?? null; | ||
$message = $responseJson['message'] ?? null; | ||
$code = $responseJson['code'] ?? null; | ||
} catch (JsonException $e) { | ||
// Ignore JSON exceptions, response object is available instead. | ||
} | ||
|
||
parent::__construct($message, $request, $response, $previous); | ||
$this->code = $code; | ||
} | ||
|
||
/** | ||
* Get the status code as returned by the B2 API. | ||
*/ | ||
public function getStatus(): ?string | ||
{ | ||
return $this->statusCode; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/BadAuthTokenException.php → ...eptions/Request/BadAuthTokenException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class BadAuthTokenException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/BadRequestException.php → ...xceptions/Request/BadRequestException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class BadRequestException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/CapExceededException.php → ...ceptions/Request/CapExceededException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class CapExceededException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class ConflictException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class DownloadCapExceededException extends CapExceededException {} |
2 changes: 1 addition & 1 deletion
2
...ceptions/DuplicateBucketNameException.php → .../Request/DuplicateBucketNameException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class DuplicateBucketNameException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class ExpiredAuthTokenException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/FileNotPresentException.php → ...tions/Request/FileNotPresentException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class FileNotPresentException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class InvalidBucketIdException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class InvalidFileIdException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class MethodNotAllowedException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class NotFoundException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class OutOfRangeException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class RangeNotSatisfiableException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class RequestTimeoutException extends B2APIException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class ServiceUnavailableException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
...xceptions/StorageCapExceededException.php → ...s/Request/StorageCapExceededException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class StorageCapExceededException extends CapExceededException {} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/TooManyBucketsException.php → ...tions/Request/TooManyBucketsException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class TooManyBucketsException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
...tions/TransactionCapExceededException.php → ...quest/TransactionCapExceededException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class TransactionCapExceededException extends CapExceededException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class UnauthorizedException extends B2APIException {} |
2 changes: 1 addition & 1 deletion
2
src/Exceptions/UnsupportedException.php → ...ceptions/Request/UnsupportedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
namespace Zaxbux\BackblazeB2\Exceptions; | ||
namespace Zaxbux\BackblazeB2\Exceptions\Request; | ||
|
||
class UnsupportedException extends B2APIException {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.