Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions src/Adapter/S3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ObjectStorage\Adapter;

use Aws\Exception\AwsException;
Copy link
Collaborator Author

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.

use Aws\S3\Exception\S3Exception;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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;

Expand Down Expand Up @@ -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);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
}
}
}