From 907c686bad8e389f4d582a864be3901bced3145a Mon Sep 17 00:00:00 2001 From: James Date: Fri, 1 Jan 2021 12:14:29 +0000 Subject: [PATCH] improve exception throwing with custom exception and use of code --- src/ApiException.php | 10 ++++++++++ src/Client.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/ApiException.php diff --git a/src/ApiException.php b/src/ApiException.php new file mode 100644 index 0000000..ec83157 --- /dev/null +++ b/src/ApiException.php @@ -0,0 +1,10 @@ +code}]: {$this->message}\n"; + } + +} diff --git a/src/Client.php b/src/Client.php index bdadfc2..0e4fbd8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -54,7 +54,7 @@ class Client{ if(in_array($status_code,[200,201,204])){ return json_decode($result); }else{ - throw new \Exception("API $status_code Code: ".$result); + throw new ApiException($result,$status_code); } }