S3 error handling

This pull request does the following:

- allow retries only in the case of a recoverable error (HTTP status 500 or libCurl exception)
- perform retries with exponental backoff
- make number of retries configurable via "S3_RETRIES" env var
- style adjustments