Skip to content

resend requests that returns http errors #234

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

Conversation

fabio-sassi-spotview
Copy link
Contributor

Sometime for temporary issue, shopify http request fail, for example I found in my test logs:

Request failed with HTTP Code 520
Request failed with HTTP Code 503
OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104

If you try again a moment later, same requests are ok.

This implementation try to mitigate this problem.

I add two configuration parameters MaxRequestRetry that define how many retry are allowed (default is 0 that does not change the original behaviour of the library) and RequestRetryCallback that allow to define a callback to manage or log the retry.

For example

PHPShopify\ShopifySDK::config([
    'ShopUrl' => SHOPIFY_URL,
    'AccessToken' => SHOPIFY_API_PASSWORD,
    'MaxRequestRetry' => 5,
    'RequestRetryCallback' => function($response, $error, $retry) {
        echo "retry n=$retry: " . $error->getMessage() . "\n";
        sleep(1); 
    }
]);

Copy link
Contributor

@tareqtms tareqtms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabio-sassi-spotview
Sorry for the late review. Your solution looks good. But I think, we can avoid repeating codes for get, post, put, delete by just applying the changes into the HttpRequestJson class (instead of ShopifyResource). I will try to modify that part when I can manage time. By the time, if you can try that, just add another pull request. Thanks.

@fabio-sassi-spotview
Copy link
Contributor Author

thank you very much @tareqtms for your advice, I create pull request #240 as you suggested.

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

Successfully merging this pull request may close these issues.

2 participants