Skip to content

Commit

Permalink
Merge pull request #8 from Gman98ish/validation
Browse files Browse the repository at this point in the history
Added validation exception
  • Loading branch information
Gman98ish authored Mar 17, 2022
2 parents 5731c09 + 83b8ccc commit 9214bb0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
});
}

Expand Down
15 changes: 15 additions & 0 deletions src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace UKFast\SimpleSDK\Exceptions;

use Exception;

class ValidationException extends Exception
{
public $errors;

public function __construct($errors)
{
$this->errors = $errors;
}
}

0 comments on commit 9214bb0

Please sign in to comment.