This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
generated from lizhineng/skeleton-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handles HTTP client and server exceptions
- Loading branch information
Showing
5 changed files
with
100 additions
and
30 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 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,38 @@ | ||
<?php | ||
|
||
namespace Dew\Tablestore\Exceptions; | ||
|
||
use Exception; | ||
use Protos\Error; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class TablestoreException extends Exception | ||
{ | ||
/** | ||
* Create a Tablestore exception. | ||
*/ | ||
public function __construct( | ||
protected Error $e | ||
) { | ||
parent::__construct($e->getMessage()); | ||
} | ||
|
||
/** | ||
* Create a Tablestore exception from error response. | ||
*/ | ||
public static function fromResponse(ResponseInterface $response): self | ||
{ | ||
$error = new Error; | ||
$error->mergeFromString($response->getBody()->getContents()); | ||
|
||
return new self($error); | ||
} | ||
|
||
/** | ||
* Get the error message. | ||
*/ | ||
public function getError(): Error | ||
{ | ||
return $this->e; | ||
} | ||
} |
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