Skip to content

Commit

Permalink
Regard permission denied as legal when create graph connection (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Linary authored Nov 11, 2020
1 parent 1b112c2 commit eb21cec
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.baidu.hugegraph.util;

import java.util.Set;

import org.springframework.web.util.UriComponentsBuilder;

import com.baidu.hugegraph.common.Constant;
Expand All @@ -29,11 +31,16 @@
import com.baidu.hugegraph.rest.ClientException;
import com.baidu.hugegraph.structure.gremlin.Result;
import com.baidu.hugegraph.structure.gremlin.ResultSet;
import com.google.common.collect.ImmutableSet;

public final class HugeClientUtil {

private static final String DEFAULT_PROTOCOL = "http";

private static final Set<String> ACCEPTABLE_EXCEPTIONS = ImmutableSet.of(
"Permission denied: execute Resource"
);

public static HugeClient tryConnect(GraphConnection connection) {
String graph = connection.getGraph();
String host = connection.getHost();
Expand Down Expand Up @@ -105,11 +112,25 @@ public static HugeClient tryConnect(GraphConnection connection) {
throw new ExternalException("graph-connection.graph.unexist", e,
graph, host, port);
}
throw e;
if (!isAcceptable(message)) {
throw e;
}
} catch (Exception e) {
client.close();
throw e;
}
return client;
}

private static boolean isAcceptable(String message) {
if (message == null) {
return false;
}
for (String acceptableMessage : ACCEPTABLE_EXCEPTIONS) {
if (message.contains(acceptableMessage)) {
return true;
}
}
return false;
}
}

0 comments on commit eb21cec

Please sign in to comment.