laravel-shopify
laravel-shopify copied to clipboard
Empty Validation Exception
Shopify is a bit inconsistent with their error responses. In particular: while calling cancelOrder I found that they don't return an array of errors
, but just a single line attribute error
.
The Handler specifically looks for the errors
key in the response JSON, and returns an empty array by default if it's not found. This led me to getting validation exceptions like this:
Validation failed due to: [] {"exception":"[object] (Signifly\Shopify\Exceptions\ValidationException(code: 0): Validation failed due to: [] ...
which obviously isn't great for trying to handle errors.
This could be resolved with something like the following:
if ($response->status() === 422) {
$errors = $response->json('errors', []);
if (empty($errors)) {
$errors = $response->json('error', []);
if (!empty($errors)) {
$errors = [$errors];
}
}
throw new ValidationException($errors);
}
but I didn't want to impose with another PR, so leaving this here as an issue for you to determine the best solution.