feat: improved exception handling
This commit is contained in:
+12
-14
@@ -46,7 +46,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getPersonalData(string $email, string $password): Notification|PersonalData
|
||||
{
|
||||
@@ -64,7 +63,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function register(RegistrationData $registrationData): Notification
|
||||
{
|
||||
@@ -88,7 +86,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function resetPassword(string $email): Notification
|
||||
{
|
||||
@@ -105,7 +102,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function updatePersonalData(
|
||||
string $email,
|
||||
@@ -129,7 +125,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function updateNewsletterRegistration(string $email, string $password, PersonalData $personalData): Notification|PersonalData
|
||||
{
|
||||
@@ -152,7 +147,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getBookings(string $email, string $password): Notification|BaseData
|
||||
{
|
||||
@@ -168,6 +162,9 @@ class ApiClient
|
||||
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
*/
|
||||
public function getBooking(string $email, string $password, int $id): Notification|Booking
|
||||
{
|
||||
$data = [
|
||||
@@ -185,7 +182,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function updateBooking(BookingData $formData, bool $debug = false): Notification|BookingUpdate
|
||||
{
|
||||
@@ -204,7 +200,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getMutableData(int $id): Notification|BaseData
|
||||
{
|
||||
@@ -221,7 +216,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getAvailabilities(int $id): Notification|BaseData
|
||||
{
|
||||
@@ -237,7 +231,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getCrmAttributes(string $email, string $password): Notification|CrmAttributes
|
||||
{
|
||||
@@ -255,7 +248,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getBaseData(string $type): Notification|BaseData
|
||||
{
|
||||
@@ -270,7 +262,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
public function getDocuments(string $email, string $password, int $id, string $type): mixed
|
||||
{
|
||||
@@ -289,7 +280,6 @@ class ApiClient
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
private function sendRequest(string $type, array $data, bool $debug = false): mixed
|
||||
{
|
||||
@@ -327,7 +317,15 @@ class ApiClient
|
||||
$this->dumpXmlToFile('response', $requestId, $xml);
|
||||
}
|
||||
|
||||
return $this->responseParser->parseXmlString($type, $xml);
|
||||
try {
|
||||
return $this->responseParser->parseXmlString($type, $xml);
|
||||
} catch (ResponseParserException $e) {
|
||||
$this->dumpXmlToFile('response', $requestId, $xml);
|
||||
}
|
||||
|
||||
throw new ApiClientException('Unexpected response received from API', [
|
||||
'request_id' => $requestId,
|
||||
]);
|
||||
}
|
||||
|
||||
private function dumpXmlToFile(string $type, string $requestId, string $body): void
|
||||
|
||||
Reference in New Issue
Block a user