commercetools / sphere-node-sdk

Officially supported Node.js SDK library for working with the SPHERE.IO HTTP API, with OAuth2 support.
http://sphereio.github.io/sphere-node-sdk/
MIT License
16 stars 8 forks source link

Should retry on concurrent modification error #129

Open butenkor opened 8 years ago

butenkor commented 8 years ago

Expected behavior

If i update product and concurrent modification exception is thrown by API, SDK should use new version from API error response and retry payload. This behaviour should be configurable (i.e.: on client instantiation. Nice to have: per endpoint). More details on error: http://dev.commercetools.com/http-api-errors.html#409-conflict

Actual behavior

It rejects with concurrent modification error from API

Steps to reproduce the behavior

Update product attribute and publish at the same time

emmenko commented 8 years ago

This can be solved by using the retry util from sphere-node-utils, it doesn't need to be in the sdk

butenkor commented 8 years ago

How this can be solved with sphere-node-utils? Can you provide an example? Also why would every user need to implement retry if it could be done easily by SDK? It is common for SDKs to provide such functionality: https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/retry/RetryPolicy.java

https://packagist.org/packages/postmen/sdk-php#user-content-automatic-retry-on-retryable-error

emmenko commented 8 years ago

I forgot that the API now returns the current version in the error message. http://dev.commercetools.com/http-api-errors.html#409-conflict

It would be easier to implement then. It would be good if you can provide a PR ;)