1
1
package com .crowdin .cli .client ;
2
2
3
+ import com .crowdin .cli .utils .Utils ;
3
4
import com .crowdin .client .branches .model .*;
4
5
import com .crowdin .client .core .model .PatchRequest ;
5
6
import com .crowdin .client .labels .model .AddLabelRequest ;
@@ -212,10 +213,16 @@ public Long uploadStorage(String fileName, InputStream content) throws Response
212
213
Map <BiPredicate <String , String >, ResponseException > errorHandlers = new LinkedHashMap <BiPredicate <String , String >, ResponseException >() {{
213
214
put ((code , message ) -> StringUtils .containsAny (message , "streamIsEmpty" , "Stream size is null. Not empty content expected" ),
214
215
new EmptyFileException ("Not empty content expected" ));
216
+ put ((code , message ) -> Utils .isServerErrorCode (code ), new RepeatException ("Server Error" ));
217
+ put ((code , message ) -> message .contains ("Request aborted" ), new RepeatException ("Request aborted" ));
218
+ put ((code , message ) -> message .contains ("Connection reset" ), new RepeatException ("Connection reset" ));
215
219
}};
216
- Storage storage = executeRequest (errorHandlers , () -> this .client .getStorageApi ()
217
- .addStorage (fileName , content )
218
- .getData ());
220
+ Storage storage = executeRequestWithPossibleRetries (
221
+ errorHandlers ,
222
+ () -> this .client .getStorageApi ().addStorage (fileName , content ).getData (),
223
+ 3 ,
224
+ 2 * 1000
225
+ );
219
226
return storage .getId ();
220
227
}
221
228
@@ -244,28 +251,38 @@ public void deleteDirectory(Long directoryId) {
244
251
@ Override
245
252
public void updateSource (Long sourceId , UpdateFileRequest request ) throws ResponseException {
246
253
Map <BiPredicate <String , String >, ResponseException > errorHandlers = new LinkedHashMap <BiPredicate <String , String >, ResponseException >() {{
247
- put ((code , message ) -> message .contains ("File from storage with id #" + request .getStorageId () + " was not found" ), new RepeatException ());
254
+ put ((code , message ) -> message .contains ("File from storage with id #" + request .getStorageId () + " was not found" ), new RepeatException ("File not found in the storage" ));
255
+ put ((code , message ) -> Utils .isServerErrorCode (code ), new RepeatException ("Server Error" ));
256
+ put ((code , message ) -> message .contains ("Request aborted" ), new RepeatException ("Request aborted" ));
257
+ put ((code , message ) -> message .contains ("Connection reset" ), new RepeatException ("Connection reset" ));
248
258
put ((code , message ) -> StringUtils .contains (message , "Invalid SRX specified" ), new ResponseException ("Invalid SRX file specified" ));
249
259
put ((code , message ) -> code .equals ("409" ), new FileInUpdateException ());
250
260
}};
251
- executeRequestWithPossibleRetry (
261
+ executeRequestWithPossibleRetries (
252
262
errorHandlers ,
253
- () -> this .client .getSourceFilesApi ()
254
- .updateOrRestoreFile (this .projectId , sourceId , request ));
263
+ () -> this .client .getSourceFilesApi ().updateOrRestoreFile (this .projectId , sourceId , request ),
264
+ 3 ,
265
+ 2 * 1000
266
+ );
255
267
}
256
268
257
269
@ Override
258
270
public FileInfo addSource (AddFileRequest request ) throws ResponseException {
259
271
Map <BiPredicate <String , String >, ResponseException > errorHandlers = new LinkedHashMap <BiPredicate <String , String >, ResponseException >() {{
260
- put ((code , message ) -> message .contains ("File from storage with id #" + request .getStorageId () + " was not found" ), new RepeatException ());
272
+ put ((code , message ) -> message .contains ("File from storage with id #" + request .getStorageId () + " was not found" ), new RepeatException ("File not found in the storage" ));
273
+ put ((code , message ) -> Utils .isServerErrorCode (code ), new RepeatException ("Server Error" ));
274
+ put ((code , message ) -> message .contains ("Request aborted" ), new RepeatException ("Request aborted" ));
275
+ put ((code , message ) -> message .contains ("Connection reset" ), new RepeatException ("Connection reset" ));
261
276
put ((code , message ) -> StringUtils .contains (message , "Name must be unique" ), new ExistsResponseException ());
262
277
put ((code , message ) -> StringUtils .contains (message , "Invalid SRX specified" ), new ResponseException ("Invalid SRX file specified" ));
263
278
put ((code , message ) -> StringUtils .containsAny (message , "isEmpty" , "Value is required and can't be empty" ), new EmptyFileException ("Value is required and can't be empty" ));
264
279
}};
265
- return executeRequestWithPossibleRetry (
280
+ return executeRequestWithPossibleRetries (
266
281
errorHandlers ,
267
- () -> this .client .getSourceFilesApi ()
268
- .addFile (this .projectId , request ).getData ());
282
+ () -> this .client .getSourceFilesApi ().addFile (this .projectId , request ).getData (),
283
+ 3 ,
284
+ 2 * 1000
285
+ );
269
286
}
270
287
271
288
@ Override
@@ -303,12 +320,17 @@ public void uploadTranslations(String languageId, UploadTranslationsRequest requ
303
320
put ((code , message ) -> code .equals ("0" ) && message .equals ("File is not allowed for language" ),
304
321
new WrongLanguageException ());
305
322
put ((code , message ) -> message .contains ("File from storage with id #" + request .getStorageId () + " was not found" ),
306
- new RepeatException ());
323
+ new RepeatException ("File not found in the storage" ));
324
+ put ((code , message ) -> Utils .isServerErrorCode (code ), new RepeatException ("Server Error" ));
325
+ put ((code , message ) -> message .contains ("Request aborted" ), new RepeatException ("Request aborted" ));
326
+ put ((code , message ) -> message .contains ("Connection reset" ), new RepeatException ("Connection reset" ));
307
327
}};
308
- executeRequestWithPossibleRetry (
328
+ executeRequestWithPossibleRetries (
309
329
errorhandlers ,
310
- () -> this .client .getTranslationsApi ()
311
- .uploadTranslations (this .projectId , languageId , request ));
330
+ () -> this .client .getTranslationsApi ().uploadTranslations (this .projectId , languageId , request ),
331
+ 3 ,
332
+ 2 * 1000
333
+ );
312
334
}
313
335
314
336
@ Override
@@ -321,13 +343,16 @@ public void uploadTranslationStringsBased(String languageId, UploadTranslationsS
321
343
public ProjectBuild startBuildingTranslation (BuildProjectTranslationRequest request ) throws ResponseException {
322
344
Map <BiPredicate <String , String >, ResponseException > errorHandler = new LinkedHashMap <BiPredicate <String , String >, ResponseException >() {{
323
345
put ((code , message ) -> code .equals ("409" ) && message .contains ("Another build is currently in progress" ),
324
- new RepeatException ());
346
+ new RepeatException ("Another build is currently in progress" ));
347
+ put ((code , message ) -> Utils .isServerErrorCode (code ), new RepeatException ("Server Error" ));
348
+ put ((code , message ) -> message .contains ("Request aborted" ), new RepeatException ("Request aborted" ));
349
+ put ((code , message ) -> message .contains ("Connection reset" ), new RepeatException ("Connection reset" ));
325
350
}};
326
351
return executeRequestWithPossibleRetries (
327
352
errorHandler ,
328
353
() -> this .client .getTranslationsApi ().buildProjectTranslation (this .projectId , request ).getData (),
329
354
3 ,
330
- 60 * 100
355
+ 6 * 1000
331
356
);
332
357
}
333
358
0 commit comments