-
Notifications
You must be signed in to change notification settings - Fork 1
Help library users react better to Object Storage failures #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| namespace ObjectStorage\Adapter; | ||
|
|
||
| use Aws\Exception\AwsException; | ||
| use Aws\S3\Exception\S3Exception; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S3Exception are thrown when there are S3 specific errors. |
||
| use Aws\S3\S3Client; | ||
| use InvalidArgumentException; | ||
|
|
||
|
|
@@ -106,35 +108,53 @@ public function setCannedAcl(string $cannedAcl) | |
|
|
||
| public function setData($key, $data) | ||
| { | ||
| $this->s3client->putObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| 'Body' => $data, | ||
| 'ACL' => $this->cannedAcl, | ||
| ] | ||
| ); | ||
| try { | ||
| $this->s3client->putObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| 'Body' => $data, | ||
| 'ACL' => $this->cannedAcl, | ||
| ] | ||
| ); | ||
| } catch (S3Exception $e) { | ||
| throw new AdapterException('Failed to store data because of an S3 error', null, $e); | ||
| } catch (AwsException $e) { | ||
| throw new AdapterException('Failed to store data because of an AWS error', null, $e); | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So all this change really does is catch AWS and S3 exceptions and throw AdapterException instead. |
||
| } | ||
|
|
||
| public function getData($key) | ||
| { | ||
| $result = $this->s3client->getObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| ] | ||
| ); | ||
| try { | ||
| $result = $this->s3client->getObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| ] | ||
| ); | ||
| } catch (S3Exception $e) { | ||
| throw new AdapterException('Failed to retrieve data because of an S3 error', null, $e); | ||
| } catch (AwsException $e) { | ||
| throw new AdapterException('Failed to retrieve data because of an AWS error', null, $e); | ||
| } | ||
|
|
||
| return (string) $result['Body']; | ||
| } | ||
|
|
||
| public function deleteData($key) | ||
| { | ||
| $this->s3client->deleteObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| ] | ||
| ); | ||
| try { | ||
| $this->s3client->deleteObject( | ||
| [ | ||
| 'Bucket' => $this->bucketname, | ||
| 'Key' => $this->prefix . $key, | ||
| ] | ||
| ); | ||
| } catch (S3Exception $e) { | ||
| throw new AdapterException('Failed to delete data because of an S3 error', null, $e); | ||
| } catch (AwsException $e) { | ||
| throw new AdapterException('Failed to delete data because of an AWS error', null, $e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AwsException are thrown when there are generic AWS errors.