|
2 | 2 |
|
3 | 3 | namespace ObjectStorage\Adapter; |
4 | 4 |
|
| 5 | +use Aws\Exception\AwsException; |
| 6 | +use Aws\S3\Exception\S3Exception; |
5 | 7 | use Aws\S3\S3Client; |
6 | 8 | use InvalidArgumentException; |
7 | 9 |
|
@@ -106,35 +108,53 @@ public function setCannedAcl(string $cannedAcl) |
106 | 108 |
|
107 | 109 | public function setData($key, $data) |
108 | 110 | { |
109 | | - $this->s3client->putObject( |
110 | | - [ |
111 | | - 'Bucket' => $this->bucketname, |
112 | | - 'Key' => $this->prefix . $key, |
113 | | - 'Body' => $data, |
114 | | - 'ACL' => $this->cannedAcl, |
115 | | - ] |
116 | | - ); |
| 111 | + try { |
| 112 | + $this->s3client->putObject( |
| 113 | + [ |
| 114 | + 'Bucket' => $this->bucketname, |
| 115 | + 'Key' => $this->prefix . $key, |
| 116 | + 'Body' => $data, |
| 117 | + 'ACL' => $this->cannedAcl, |
| 118 | + ] |
| 119 | + ); |
| 120 | + } catch (S3Exception $e) { |
| 121 | + throw new AdapterException('Failed to store data because of an S3 error', null, $e); |
| 122 | + } catch (AwsException $e) { |
| 123 | + throw new AdapterException('Failed to store data because of an AWS error', null, $e); |
| 124 | + } |
117 | 125 | } |
118 | 126 |
|
119 | 127 | public function getData($key) |
120 | 128 | { |
121 | | - $result = $this->s3client->getObject( |
122 | | - [ |
123 | | - 'Bucket' => $this->bucketname, |
124 | | - 'Key' => $this->prefix . $key, |
125 | | - ] |
126 | | - ); |
| 129 | + try { |
| 130 | + $result = $this->s3client->getObject( |
| 131 | + [ |
| 132 | + 'Bucket' => $this->bucketname, |
| 133 | + 'Key' => $this->prefix . $key, |
| 134 | + ] |
| 135 | + ); |
| 136 | + } catch (S3Exception $e) { |
| 137 | + throw new AdapterException('Failed to retrieve data because of an S3 error', null, $e); |
| 138 | + } catch (AwsException $e) { |
| 139 | + throw new AdapterException('Failed to retrieve data because of an AWS error', null, $e); |
| 140 | + } |
127 | 141 |
|
128 | 142 | return (string) $result['Body']; |
129 | 143 | } |
130 | 144 |
|
131 | 145 | public function deleteData($key) |
132 | 146 | { |
133 | | - $this->s3client->deleteObject( |
134 | | - [ |
135 | | - 'Bucket' => $this->bucketname, |
136 | | - 'Key' => $this->prefix . $key, |
137 | | - ] |
138 | | - ); |
| 147 | + try { |
| 148 | + $this->s3client->deleteObject( |
| 149 | + [ |
| 150 | + 'Bucket' => $this->bucketname, |
| 151 | + 'Key' => $this->prefix . $key, |
| 152 | + ] |
| 153 | + ); |
| 154 | + } catch (S3Exception $e) { |
| 155 | + throw new AdapterException('Failed to delete data because of an S3 error', null, $e); |
| 156 | + } catch (AwsException $e) { |
| 157 | + throw new AdapterException('Failed to delete data because of an AWS error', null, $e); |
| 158 | + } |
139 | 159 | } |
140 | 160 | } |
0 commit comments