Skip to content
Permalink
Browse files
Regard permission denied as legal when create graph connection (#251)
  • Loading branch information
Linary committed Nov 11, 2020
1 parent 1b112c2 commit eb21cec0789208db33ee46779f049db22f20bb50
Showing 1 changed file with 22 additions and 1 deletion.
@@ -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;
@@ -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();
@@ -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.