Skip to content

Commit

Permalink
added try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat committed Jun 3, 2024
1 parent 5d256d3 commit 6164a8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.common.intercept.InterceptException;
import org.apache.pulsar.common.policies.data.ErrorData;
import org.apache.pulsar.common.util.ObjectMapperFactory;
Expand All @@ -36,6 +37,7 @@
/**
* Exception handler for handle exception.
*/
@Slf4j
public class ExceptionHandler {

public void handle(ServletResponse response, Exception ex) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,40 @@ public CompletableFuture<Void> readAsync(String path, OutputStream outputStream)

@Override
public CompletableFuture<Void> deleteAsync(String path) {
if (getPath(path).delete()) {
return CompletableFuture.completedFuture(null);
} else {
CompletableFuture<Void> f = new CompletableFuture<>();
f.completeExceptionally(new IOException("Failed to delete file at " + path));
return f;
try {
if (getPath(path).delete()) {
return CompletableFuture.completedFuture(null);
} else {
CompletableFuture<Void> f = new CompletableFuture<>();
f.completeExceptionally(new IOException("Failed to delete file at " + path));
return f;
}
} catch (IOException e) {
return CompletableFuture.failedFuture(e);
}
}

@Override
public CompletableFuture<List<String>> listAsync(String path) {
String[] files = getPath(path).list();
if (files == null) {
return CompletableFuture.completedFuture(Collections.emptyList());
} else {
return CompletableFuture.completedFuture(Arrays.asList(files));
try {
String[] files = getPath(path).list();
if (files == null) {
return CompletableFuture.completedFuture(Collections.emptyList());
} else {
return CompletableFuture.completedFuture(Arrays.asList(files));
}
} catch (IOException e) {
return CompletableFuture.failedFuture(e);
}
}

@Override
public CompletableFuture<Boolean> existAsync(String path) {
return CompletableFuture.completedFuture(getPath(path).exists());
try {
return CompletableFuture.completedFuture(getPath(path).exists());
} catch (IOException e) {
return CompletableFuture.failedFuture(e);
}
}

@Override
Expand Down

0 comments on commit 6164a8a

Please sign in to comment.