diff --git a/README.md b/README.md index f2a743d3..067876ca 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This is the official Help Scout PHP client. This client contains methods for eas * [Webhooks](#webhooks) * [Workflows](#workflows) * [Error Handling](#error-handling) + * [Validation](#validation) * [Pagination](#pagination) * [Testing](#testing) @@ -822,6 +823,29 @@ $client->workflows()->updateStatus($id, 'active'); Any exception thrown by the client directly will implement `HelpScout\Api\Exception` and HTTP errors will result in `Http\Client\Exception\RequestException` being thrown. +### Validation + +You'll encounter a `ValidationErrorException` if there are any validation errors with the request you submitted to the API. Here's a quick example on how to use that exception: + +```php +try { + // do something +} catch (\HelpScout\Api\Exception\ValidationErrorException $e) { + $error = $e->getError(); + + var_dump( + // A reference id for that request. Including this anytime you contact Help Scout support will enable + // us to help you much more quickly + $error->getLogRef(), + + // Details about the invalid fields in the request + $error->getErrors() + ); + exit; +} +``` + + ## Pagination When fetching a collection of entities the client will return an instance of `HelpScout\Api\Entity\Collection`. If the end point supports pagination then it will return an instance of `HelpScout\Api\Entity\PagedCollection`. diff --git a/src/Http/Hal/VndError.php b/src/Http/Hal/VndError.php index a28ce89e..aadc5c5e 100644 --- a/src/Http/Hal/VndError.php +++ b/src/Http/Hal/VndError.php @@ -47,6 +47,9 @@ public function getMessage(): string } /** + * If populated, include this in any support requests you submit to HelpScout which will help us identify + * any issues you encounter. + * * @return string|null */ public function getLogRef()