Skip to content

Commit 8e4825a

Browse files
author
Skaelv
committed
add an exception section to readme
1 parent 702df7a commit 8e4825a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,29 @@ $client->nextPage($response["pages"]);
300300
```
301301

302302

303+
## Exceptions
304+
305+
Exceptions are handled by [Guzzle](https://github.com/guzzle/guzzle).
306+
The Intercom API may return an unsuccessful HTTP response, for example when a resource is not found (404).
307+
If you want to catch errors you can wrap your API call into a try/catch:
308+
309+
```php
310+
use GuzzleHttp\Exception\ClientException;
311+
312+
try {
313+
$user = $client->users->getUser("570680a8a1bcbca8a90001b9");
314+
} catch(ClientException $e) {
315+
$response = $e->getResponse();
316+
$statusCode = $response->getStatusCode();
317+
if ($statusCode == '404') {
318+
// Handle 404 error
319+
return;
320+
} else {
321+
throw $e;
322+
}
323+
}
324+
```
325+
303326
## Pull Requests
304327

305328
- **Add tests!** Your patch won't be accepted if it doesn't have tests.

0 commit comments

Comments
 (0)