|
20 | 20 | import com.google.common.cache.Cache;
|
21 | 21 | import com.google.common.cache.CacheBuilder;
|
22 | 22 | import com.google.common.cache.RemovalListener;
|
| 23 | +import com.google.common.collect.ImmutableMap; |
23 | 24 |
|
24 | 25 | import org.openqa.selenium.NoSuchSessionException;
|
25 | 26 | import org.openqa.selenium.concurrent.Regularly;
|
|
50 | 51 | import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
|
51 | 52 | import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
|
52 | 53 | import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
|
| 54 | +import static org.openqa.selenium.remote.http.Contents.asJson; |
53 | 55 | import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
|
54 | 56 | import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
|
55 | 57 | import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;
|
@@ -114,16 +116,27 @@ public HttpResponse execute(HttpRequest req) {
|
114 | 116 | span.setAttribute("error", true);
|
115 | 117 | span.setStatus(Status.CANCELLED);
|
116 | 118 |
|
| 119 | + String errorMessage = "Unable to execute request for an existing session: " + e.getMessage(); |
117 | 120 | EXCEPTION.accept(attributeMap, e);
|
118 | 121 | attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),
|
119 |
| - EventAttribute.setValue("Unable to execute request for an existing session: " + e.getMessage())); |
| 122 | + EventAttribute.setValue(errorMessage)); |
120 | 123 | span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
|
121 | 124 |
|
| 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 | + |
122 | 135 | Throwable cause = e.getCause();
|
123 | 136 | if (cause instanceof RuntimeException) {
|
124 | 137 | throw (RuntimeException) cause;
|
125 | 138 | }
|
126 |
| - throw new RuntimeException(cause); |
| 139 | + throw new RuntimeException(errorMessage, cause); |
127 | 140 | }
|
128 | 141 | }
|
129 | 142 | }
|
|
0 commit comments