Skip to content

Commit

Permalink
📝 Update exception handling example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tgeorgel committed Jan 27, 2023
1 parent 167478c commit 5387972
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ $response->header($header): string;
$response->headers(): array;
```

By default, the Request will throw a `\Illuminate\Http\Client\RequestException` if the request returns an error status code (`4xx``5xx`).
By default, the Request will throw a `RequestException` if the request returns an error (status code `4xx —> 5xx`). You can easily catch this exception and handle it as you wish :

```php
/**
Expand All @@ -208,15 +208,14 @@ public function maybeFindMyContact($contact_id)
return Bluerock\Sellsy\Core\Client::contacts()
->show($contact_id)
->entity();

# catch the RequestException
} catch (\Illuminate\Http\Client\RequestException $e) {
# return false if the contact is not found (404 error).
if ($e->response->status() === 404) {
if ($e->response->clientError() && $e->response->status() === 404) {
return false;
}

throw $e;
# throw the exception for any other status code.
throw $e;
}
}
```
Expand Down

0 comments on commit 5387972

Please sign in to comment.