From f5e75a598a617c863494b97c1da798a664768373 Mon Sep 17 00:00:00 2001 From: kw-pr <9133572+kw-pr@users.noreply.github.com> Date: Fri, 9 Apr 2021 11:47:07 +0200 Subject: [PATCH 1/2] throwPipedriveException Fixes #111 --- src/Http/Request.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Http/Request.php b/src/Http/Request.php index d12bffe..112017e 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -88,6 +88,7 @@ protected function handleResponse(Response $response) throw new ItemNotFoundException(isset($content->error) ? $content->error : "Error unknown."); } + $this->throwPipedriveException($content); throw new PipedriveException( isset($content->error) ? $content->error->message : "Error unknown." ); @@ -95,6 +96,26 @@ protected function handleResponse(Response $response) return $response; } + + /** + * Throws PipedriveException with message depending on content. + * + * @param string $content + */ + protected function throwPipedriveException($content) + { + if (!isset($content->error)) + { + throw new PipedriveException('Error unknown.'); + } + + if (property_exists($content->error, 'message')) + { + throw new PipedriveException($content->error->message); + } + + throw new PipedriveException($content->error); + } /** * Set the endpoint name. From 034dc0368dd4a4061f9f01cb98f43c4dbcf4f4cc Mon Sep 17 00:00:00 2001 From: kw-pr <9133572+kw-pr@users.noreply.github.com> Date: Fri, 9 Apr 2021 13:18:35 +0200 Subject: [PATCH 2/2] Cleanup --- src/Http/Request.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index 112017e..e66a7e5 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -89,9 +89,6 @@ protected function handleResponse(Response $response) } $this->throwPipedriveException($content); - throw new PipedriveException( - isset($content->error) ? $content->error->message : "Error unknown." - ); } return $response;