@@ -559,24 +559,39 @@ The Seam API parses these params with the corresponding [parser].
559559[ reference implementation ] : https://github.com/seamapi/url-search-params-serializer
560560[ parser ] : https://github.com/seamapi/url-search-params-parser
561561
562- #### Errors
562+ ### Error Handling
563563
564564Every exception the SDK raises implements ` Seam\SeamException ` , so it can be
565565caught as a group. An API error is a ` Seam\HttpApiError ` carrying
566566` getErrorCode() ` , ` getStatusCode() ` and ` getRequestId() ` , with
567567` Seam\HttpUnauthorizedError ` and ` Seam\HttpInvalidInputError ` as the two
568568specific cases worth catching on their own.
569569
570+ #### Validation errors
571+
572+ When the API rejects a request because a parameter is invalid, it throws an
573+ ` HttpInvalidInputError ` . Look up messages for a parameter you are already
574+ rendering, for example a field in a form:
575+
570576``` php
571- use Seam\HttpApiError;
572577use Seam\HttpInvalidInputError;
573578
574579try {
575- $seam->devices->get(device_id: $device_id );
580+ $seam->devices->list(device_ids: ["not-a-uuid"] );
576581} catch (HttpInvalidInputError $error) {
577- print_r($error->getValidationErrorMessages("device_id"));
578- } catch (HttpApiError $error) {
579- print $error->getErrorCode();
582+ print_r($error->getValidationErrorMessages("device_ids"));
583+ }
584+ ```
585+
586+ Or read every parameter that failed validation to summarize the request:
587+
588+ ``` php
589+ foreach ($error->validation_errors as $validation_error) {
590+ printf(
591+ "%s: %s\n",
592+ $validation_error->parameter_name,
593+ implode(", ", $validation_error->error_messages),
594+ );
580595}
581596```
582597
0 commit comments