Skip to content

Commit

Permalink
Little fix - add handler for response about invalid srx file
Browse files Browse the repository at this point in the history
  • Loading branch information
frombetelgeuse committed Sep 13, 2021
1 parent 148f368 commit af6407b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ public void deleteDirectory(Long directoryId) {
}

@Override
public void updateSource(Long sourceId, UpdateFileRequest request) {
public void updateSource(Long sourceId, UpdateFileRequest request) throws ResponseException {
Map<BiPredicate<String, String>, ResponseException> errorHandlers = new LinkedHashMap<BiPredicate<String, String>, ResponseException>() {{
put((code, message) -> message.contains("File from storage with id #" + request.getStorageId() + " was not found"), new RepeatException());
put((code, message) -> StringUtils.contains(message, "Invalid SRX specified"), new ResponseException("Invalid SRX file specified"));
}};
executeRequestWithPossibleRetry(
(code, message) -> message.contains("File from storage with id #" + request.getStorageId() + " was not found"),
errorHandlers,
() -> this.client.getSourceFilesApi()
.updateOrRestoreFile(this.projectId, sourceId, request));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface ProjectClient extends Client {

void deleteDirectory(Long directoryId);

void updateSource(Long sourceId, UpdateFileRequest request);
void updateSource(Long sourceId, UpdateFileRequest request) throws ResponseException ;

void addSource(AddFileRequest request) throws ResponseException;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/crowdin/cli/client/ResponseException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
package com.crowdin.cli.client;

public class ResponseException extends Exception {

public ResponseException() {

}

public ResponseException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void testAddDirectoryThrows() throws ResponseException {
}

@Test
public void testUpdateSource() {
public void testUpdateSource() throws ResponseException {
FileResponseObject response = new FileResponseObject() {{
setData(new File());
}};
Expand Down

0 comments on commit af6407b

Please sign in to comment.