Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Validation Exception #54

Open
BrandonKerr opened this issue Nov 10, 2023 · 0 comments
Open

Empty Validation Exception #54

BrandonKerr opened this issue Nov 10, 2023 · 0 comments

Comments

@BrandonKerr
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant