Skip to content

Commit

Permalink
Handle Guzzle exception during query
Browse files Browse the repository at this point in the history
  • Loading branch information
TeddyBear06 committed Aug 23, 2022
1 parent 60ab005 commit ad38e84
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
32 changes: 24 additions & 8 deletions docs/classes/TeddyBear06-EdgeDbPhp-EdgeDbHttpClient.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2 class="phpdocumentor-content__title">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">15</span>
<span class="phpdocumentor-element-found-in__line">16</span>

</aside>

Expand Down Expand Up @@ -211,7 +211,7 @@ <h4 class="phpdocumentor-element__name" id="property_client">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">51</span>
<span class="phpdocumentor-element-found-in__line">52</span>

</aside>

Expand Down Expand Up @@ -244,7 +244,7 @@ <h4 class="phpdocumentor-element__name" id="property_database">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">37</span>
<span class="phpdocumentor-element-found-in__line">38</span>

</aside>

Expand Down Expand Up @@ -277,7 +277,7 @@ <h4 class="phpdocumentor-element__name" id="property_debug">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">44</span>
<span class="phpdocumentor-element-found-in__line">45</span>

</aside>

Expand Down Expand Up @@ -310,7 +310,7 @@ <h4 class="phpdocumentor-element__name" id="property_hostname">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">23</span>
<span class="phpdocumentor-element-found-in__line">24</span>

</aside>

Expand Down Expand Up @@ -343,7 +343,7 @@ <h4 class="phpdocumentor-element__name" id="property_port">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">30</span>
<span class="phpdocumentor-element-found-in__line">31</span>

</aside>

Expand Down Expand Up @@ -380,7 +380,7 @@ <h4 class="phpdocumentor-element__name" id="method___construct">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">61</span>
<span class="phpdocumentor-element-found-in__line">62</span>

</aside>

Expand Down Expand Up @@ -448,7 +448,7 @@ <h4 class="phpdocumentor-element__name" id="method_query">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/EdgeDbHttpClient.php"><a href="files/src-edgedbhttpclient.html"><abbr title="src/EdgeDbHttpClient.php">EdgeDbHttpClient.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">79</span>
<span class="phpdocumentor-element-found-in__line">82</span>

</aside>

Expand All @@ -472,6 +472,22 @@ <h5 class="phpdocumentor-argument-list__heading">Parameters</h5>
</dl>


<h5 class="phpdocumentor-tag-list__heading" id="tags">
Tags
<a href="#tags" class="headerlink"><i class="fas fa-link"></i></a>
</h5>
<dl class="phpdocumentor-tag-list">
<dt class="phpdocumentor-tag-list__entry">
<span class="phpdocumentor-tag__name">throws</span>
</dt>
<dd class="phpdocumentor-tag-list__definition">
<span class="phpdocumentor-tag-link"><a href="classes/TeddyBear06-EdgeDbPhp-EdgeDbException.html"><abbr title="\TeddyBear06\EdgeDbPhp\EdgeDbException">EdgeDbException</abbr></a></span>

<section class="phpdocumentor-description"><p>If an error happens while sending the request.</p>
</section>

</dd>
</dl>

<h5 class="phpdocumentor-return-value__heading">Return values</h5>
<span class="phpdocumentor-signature__response_type"><a href="classes/TeddyBear06-EdgeDbPhp-EdgeDbHttpResponse.html"><abbr title="\TeddyBear06\EdgeDbPhp\EdgeDbHttpResponse">EdgeDbHttpResponse</abbr></a></span>
Expand Down
12 changes: 9 additions & 3 deletions src/EdgeDbHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TeddyBear06\EdgeDbPhp;

use TeddyBear06\EdgeDbPhp\EdgeDbHttpResponse;
use TeddyBear06\EdgeDbPhp\EdgeDbException;
use TeddyBear06\EdgeDbPhp\EdgeQlQuery;
use GuzzleHttp\Client;

Expand Down Expand Up @@ -75,6 +76,8 @@ public function __construct(string $hostname = '127.0.0.1', int $port = 10700, s
* @var EdgeQlQuery $query The EdgeQL query.
*
* @return EdgeDbHttpResponse
*
* @throws EdgeDbException If an error happens while sending the request.
*/
public function query(EdgeQlQuery $query): EdgeDbHttpResponse
{
Expand All @@ -83,9 +86,12 @@ public function query(EdgeQlQuery $query): EdgeDbHttpResponse
'debug' => $this->debug
];

$response = $this->client->request('POST', '', $options);

return new EdgeDbHttpResponse($response->getBody());
try {
$response = $this->client->request('POST', '', $options);
return new EdgeDbHttpResponse($response->getBody());
} catch (\Throwable $t) {
throw new EdgeDbException('EdgeDB client request failed', $t->getCode(), $t);
}
}

}

0 comments on commit ad38e84

Please sign in to comment.