Skip to content

Commit

Permalink
refactor: change error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Orkuncakilkaya committed Jul 25, 2024
1 parent 6e0d193 commit 7e154d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function getConfig()
* @throws \Fingerprint\ServerAPI\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @throws SerializationException
* @throws GuzzleException
* @return array{ \Fingerprint\ServerAPI\Model\EventResponse|null, \Psr\Http\Message\ResponseInterface }
*/
public function getEvent($request_id)
Expand Down Expand Up @@ -126,7 +127,7 @@ public function getEvent($request_id)
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
throw new SerializationException($response);
throw new SerializationException($response, $e);
}

return [$serialized, $response];
Expand Down Expand Up @@ -249,6 +250,7 @@ protected function getEventRequest($request_id)
* @throws \Fingerprint\ServerAPI\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @throws SerializationException
* @throws GuzzleException
* @return array{ \Fingerprint\ServerAPI\Model\Response|null, \Psr\Http\Message\ResponseInterface }
*/
public function getVisits($visitor_id, $request_id = null, $linked_id = null, $limit = null, $pagination_key = null, $before = null)
Expand Down Expand Up @@ -292,7 +294,7 @@ public function getVisits($visitor_id, $request_id = null, $linked_id = null, $l
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
throw new SerializationException($response);
throw new SerializationException($response, $e);
}

return [$serialized, $response];
Expand Down
2 changes: 1 addition & 1 deletion src/SerializationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class SerializationException extends Exception
{
protected readonly ResponseInterface $response;

public function __construct(ResponseInterface $response, Exception $prev)
public function __construct(ResponseInterface $response, Exception $prev)
{
parent::__construct("Response from the server couldn't be serialized", $prev->getCode(), $prev);
$this->response = $response;
Expand Down
3 changes: 2 additions & 1 deletion template/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use {{invokerPackage}}\SerializationException;
* @throws {{backSlash}}{{invokerPackage}}\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @throws SerializationException
* @throws GuzzleException
* @return array{ {{#returnType}}{{{returnType}}}|null{{/returnType}}{{^returnType}}null{{/returnType}}, \Psr\Http\Message\ResponseInterface }
*/
public function {{operationId}}({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}})
Expand Down Expand Up @@ -128,7 +129,7 @@ use {{invokerPackage}}\SerializationException;
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
throw new SerializationException($response);
throw new SerializationException($response, $e);
}

return [$serialized, $response];
Expand Down
4 changes: 2 additions & 2 deletions test/FingerprintApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getEventWithHttpInfoMock($request_id): array
try {
$serialized = ObjectSerializer::deserialize($events_mock_data, EventResponse::class);
} catch (Exception $exception) {
throw new SerializationException($response);
throw new SerializationException($response, $exception);
}

return [$serialized, $response];
Expand All @@ -117,7 +117,7 @@ public function getVisitsWithHttpInfoMock($visitor_id, $request_id = null, $link
try {
$serialized = ObjectSerializer::deserialize($visits_mock_data, Response::class);
} catch (Exception $exception) {
throw new SerializationException($response);
throw new SerializationException($response, $exception);
}

return [$serialized, $response];
Expand Down

0 comments on commit 7e154d9

Please sign in to comment.