Skip to content

Commit

Permalink
Merge pull request #123 from ORudenkoAS/fix_403_handling
Browse files Browse the repository at this point in the history
Fix handling 403 Forbidden Pipedrive's response
  • Loading branch information
IsraelOrtuno authored Nov 13, 2022
2 parents 39e6490 + 4b079f0 commit 5f687a8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,31 @@ protected function handleResponse(Response $response)
throw new ItemNotFoundException(isset($content->error) ? $content->error : "Error unknown.");
}

if ($response->getStatusCode() == 401) {
throw new PipedriveException(
isset($content->error) ? $content->error : 'Unauthorized',
$response->getStatusCode()
);
}

if ($response->getStatusCode() == 403) {
throw new PipedriveException(
isset($content->error) ? $content->error : 'Forbidden',
$response->getStatusCode()
);
}

$this->throwPipedriveException($content);
}

return $response;
}

/**
* Throws PipedriveException with message depending on content.
*
* @param string $content
* @throws \Devio\Pipedrive\Exceptions\PipedriveException
*/
protected function throwPipedriveException($content)
{
Expand Down

0 comments on commit 5f687a8

Please sign in to comment.