Skip to content

Commit ae5c7cb

Browse files
committed
[grid] Add error message and exception type if the session does not exist
1 parent 8d1e4aa commit ae5c7cb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

java/src/org/openqa/selenium/grid/router/HandleSession.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.cache.Cache;
2121
import com.google.common.cache.CacheBuilder;
2222
import com.google.common.cache.RemovalListener;
23+
import com.google.common.collect.ImmutableMap;
2324

2425
import org.openqa.selenium.NoSuchSessionException;
2526
import org.openqa.selenium.concurrent.Regularly;
@@ -50,6 +51,7 @@
5051
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
5152
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
5253
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
54+
import static org.openqa.selenium.remote.http.Contents.asJson;
5355
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
5456
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
5557
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;
@@ -114,16 +116,27 @@ public HttpResponse execute(HttpRequest req) {
114116
span.setAttribute("error", true);
115117
span.setStatus(Status.CANCELLED);
116118

119+
String errorMessage = "Unable to execute request for an existing session: " + e.getMessage();
117120
EXCEPTION.accept(attributeMap, e);
118121
attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),
119-
EventAttribute.setValue("Unable to execute request for an existing session: " + e.getMessage()));
122+
EventAttribute.setValue(errorMessage));
120123
span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
121124

125+
if (e instanceof NoSuchSessionException) {
126+
HttpResponse response = new HttpResponse();
127+
response.setStatus(404);
128+
response.setContent(asJson(ImmutableMap.of(
129+
"value", req.getUri(),
130+
"message", errorMessage,
131+
"error", NoSuchSessionException.class.getName())));
132+
return response;
133+
}
134+
122135
Throwable cause = e.getCause();
123136
if (cause instanceof RuntimeException) {
124137
throw (RuntimeException) cause;
125138
}
126-
throw new RuntimeException(cause);
139+
throw new RuntimeException(errorMessage, cause);
127140
}
128141
}
129142
}

0 commit comments

Comments
 (0)