diff --git a/src/Client.php b/src/Client.php index 7b988a0..a730881 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,7 +3,10 @@ namespace UKFast\SimpleSDK; use GuzzleHttp\Client as GuzzleHttpClient; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\Utils; +use UKFast\SimpleSDK\Exceptions\ValidationException; class Client { @@ -69,6 +72,13 @@ public function createAsync($path, $body, $params = [], $headers = []) $raw = json_decode($response->getBody()->getContents()); return new SelfResponse($raw->data, $raw->meta); + }, function ($e) { + if (!$e instanceof ClientException) { + throw $e; + } + + $raw = json_decode($e->getResponse()->getBody()); + throw new ValidationException($raw->errors); }); } diff --git a/src/Exceptions/ValidationException.php b/src/Exceptions/ValidationException.php new file mode 100644 index 0000000..1c01c49 --- /dev/null +++ b/src/Exceptions/ValidationException.php @@ -0,0 +1,15 @@ +errors = $errors; + } +}