@@ -127,21 +127,18 @@ public void insert(String key, String object) throws ObjectStorageWrapperExcepti
127127 AsyncRequestBody .fromString (object ))
128128 .join ();
129129 } catch (Exception e ) {
130- Throwable cause = e .getCause ();
131- if (cause instanceof S3Exception ) {
132- Optional <S3Exception > s3Exception = findS3Exception (e );
133- if (s3Exception .isPresent ()) {
134- if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
135- throw new ConflictOccurredException (
136- String .format ("Failed to insert the object with key '%s' due to conflict" , key ),
137- s3Exception .get ());
138- }
139- if (s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
140- throw new PreconditionFailedException (
141- String .format (
142- "Failed to insert the object with key '%s' due to precondition failure" , key ),
143- s3Exception .get ());
144- }
130+ Optional <S3Exception > s3Exception = findS3Exception (e );
131+ if (s3Exception .isPresent ()) {
132+ if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
133+ throw new ConflictOccurredException (
134+ String .format ("Failed to insert the object with key '%s' due to conflict" , key ),
135+ s3Exception .get ());
136+ }
137+ if (s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
138+ throw new PreconditionFailedException (
139+ String .format (
140+ "Failed to insert the object with key '%s' due to precondition failure" , key ),
141+ s3Exception .get ());
145142 }
146143 }
147144 throw new ObjectStorageWrapperException (
@@ -159,22 +156,19 @@ public void update(String key, String object, String version)
159156 AsyncRequestBody .fromString (object ))
160157 .join ();
161158 } catch (Exception e ) {
162- Throwable cause = e .getCause ();
163- if (cause instanceof S3Exception ) {
164- Optional <S3Exception > s3Exception = findS3Exception (e );
165- if (s3Exception .isPresent ()) {
166- if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
167- throw new ConflictOccurredException (
168- String .format ("Failed to update the object with key '%s' due to conflict" , key ),
169- s3Exception .get ());
170- }
171- if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()
172- || s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
173- throw new PreconditionFailedException (
174- String .format (
175- "Failed to update the object with key '%s' due to precondition failure" , key ),
176- s3Exception .get ());
177- }
159+ Optional <S3Exception > s3Exception = findS3Exception (e );
160+ if (s3Exception .isPresent ()) {
161+ if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
162+ throw new ConflictOccurredException (
163+ String .format ("Failed to update the object with key '%s' due to conflict" , key ),
164+ s3Exception .get ());
165+ }
166+ if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()
167+ || s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
168+ throw new PreconditionFailedException (
169+ String .format (
170+ "Failed to update the object with key '%s' due to precondition failure" , key ),
171+ s3Exception .get ());
178172 }
179173 }
180174 throw new ObjectStorageWrapperException (
@@ -189,21 +183,18 @@ public void delete(String key) throws ObjectStorageWrapperException {
189183 .deleteObject (DeleteObjectRequest .builder ().bucket (bucket ).key (key ).ifMatch ("*" ).build ())
190184 .join ();
191185 } catch (Exception e ) {
192- Throwable cause = e .getCause ();
193- if (cause instanceof S3Exception ) {
194- Optional <S3Exception > s3Exception = findS3Exception (e );
195- if (s3Exception .isPresent ()) {
196- if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
197- throw new ConflictOccurredException (
198- String .format ("Failed to delete the object with key '%s' due to conflict" , key ),
199- s3Exception .get ());
200- }
201- if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()) {
202- throw new PreconditionFailedException (
203- String .format (
204- "Failed to delete the object with key '%s' due to precondition failure" , key ),
205- s3Exception .get ());
206- }
186+ Optional <S3Exception > s3Exception = findS3Exception (e );
187+ if (s3Exception .isPresent ()) {
188+ if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
189+ throw new ConflictOccurredException (
190+ String .format ("Failed to delete the object with key '%s' due to conflict" , key ),
191+ s3Exception .get ());
192+ }
193+ if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()) {
194+ throw new PreconditionFailedException (
195+ String .format (
196+ "Failed to delete the object with key '%s' due to precondition failure" , key ),
197+ s3Exception .get ());
207198 }
208199 }
209200 throw new ObjectStorageWrapperException (
@@ -219,22 +210,19 @@ public void delete(String key, String version) throws ObjectStorageWrapperExcept
219210 DeleteObjectRequest .builder ().bucket (bucket ).key (key ).ifMatch (version ).build ())
220211 .join ();
221212 } catch (Exception e ) {
222- Throwable cause = e .getCause ();
223- if (cause instanceof S3Exception ) {
224- Optional <S3Exception > s3Exception = findS3Exception (e );
225- if (s3Exception .isPresent ()) {
226- if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
227- throw new ConflictOccurredException (
228- String .format ("Failed to delete the object with key '%s' due to conflict" , key ),
229- s3Exception .get ());
230- }
231- if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()
232- || s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
233- throw new PreconditionFailedException (
234- String .format (
235- "Failed to delete the object with key '%s' due to precondition failure" , key ),
236- s3Exception .get ());
237- }
213+ Optional <S3Exception > s3Exception = findS3Exception (e );
214+ if (s3Exception .isPresent ()) {
215+ if (s3Exception .get ().statusCode () == S3ErrorCode .CONFLICT .get ()) {
216+ throw new ConflictOccurredException (
217+ String .format ("Failed to delete the object with key '%s' due to conflict" , key ),
218+ s3Exception .get ());
219+ }
220+ if (s3Exception .get ().statusCode () == S3ErrorCode .NOT_FOUND .get ()
221+ || s3Exception .get ().statusCode () == S3ErrorCode .PRECONDITION_FAILED .get ()) {
222+ throw new PreconditionFailedException (
223+ String .format (
224+ "Failed to delete the object with key '%s' due to precondition failure" , key ),
225+ s3Exception .get ());
238226 }
239227 }
240228 throw new ObjectStorageWrapperException (
0 commit comments