Skip to content

Commit

Permalink
Merge pull request #112 from kw-pr/patch-1
Browse files Browse the repository at this point in the history
throwPipedriveException
  • Loading branch information
IsraelOrtuno committed Apr 28, 2021
2 parents 5d4ff19 + 034dc03 commit 15d6151
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Http/Request.php
Expand Up @@ -88,13 +88,31 @@ protected function handleResponse(Response $response)
throw new ItemNotFoundException(isset($content->error) ? $content->error : "Error unknown.");
}

throw new PipedriveException(
isset($content->error) ? $content->error->message : "Error unknown."
);
$this->throwPipedriveException($content);
}

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.
Expand Down

0 comments on commit 15d6151

Please sign in to comment.