Skip to content

Commit 1208bbc

Browse files
Jonahsslukeis
authored andcommitted
allow custom ErrorHandler for HTTPCommandExecutor
Signed-off-by: Luke Inman-Semerau <[email protected]>
1 parent 71880db commit 1208bbc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

java/client/src/org/openqa/selenium/remote/ErrorHandler.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.openqa.selenium.remote;
2020

21+
import static org.openqa.selenium.remote.ErrorCodes.SUCCESS;
22+
2123
import com.google.common.base.Function;
2224
import com.google.common.base.Predicates;
2325
import com.google.common.base.Throwables;
@@ -33,8 +35,6 @@
3335
import java.util.List;
3436
import java.util.Map;
3537

36-
import static org.openqa.selenium.remote.ErrorCodes.SUCCESS;
37-
3838
/**
3939
* Maps exceptions to status codes for sending over the wire.
4040
*
@@ -54,7 +54,7 @@ public class ErrorHandler {
5454
private static final String UNKNOWN_METHOD = "<anonymous method>";
5555
private static final String UNKNOWN_FILE = null;
5656

57-
private final ErrorCodes errorCodes = new ErrorCodes();
57+
private ErrorCodes errorCodes;
5858

5959
private boolean includeServerErrors;
6060

@@ -68,6 +68,17 @@ public ErrorHandler() {
6868
*/
6969
public ErrorHandler(boolean includeServerErrors) {
7070
this.includeServerErrors = includeServerErrors;
71+
this.errorCodes = new ErrorCodes();
72+
}
73+
74+
/**
75+
* @param includeServerErrors Whether to include server-side details in thrown exceptions if the
76+
* information is available.
77+
* @param codes The ErrorCodes object to use for linking error codes to exceptions.
78+
*/
79+
public ErrorHandler(ErrorCodes codes, boolean includeServerErrors) {
80+
this.includeServerErrors = includeServerErrors;
81+
this.errorCodes = codes;
7182
}
7283

7384
public boolean isIncludeServerErrors() {

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public class RemoteWebDriver implements WebDriver, JavascriptExecutor,
8181
private static final Logger logger = Logger.getLogger(RemoteWebDriver.class.getName());
8282
private Level level = Level.FINE;
8383

84-
private final ErrorHandler errorHandler = new ErrorHandler();
85-
84+
private ErrorHandler errorHandler;
8685
private CommandExecutor executor;
8786
private Capabilities capabilities;
8887
private SessionId sessionId;
@@ -103,6 +102,7 @@ protected RemoteWebDriver() {
103102

104103
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,
105104
Capabilities requiredCapabilities) {
105+
this.errorHandler = new ErrorHandler();
106106
this.executor = executor;
107107

108108
init(desiredCapabilities, requiredCapabilities);
@@ -285,6 +285,10 @@ public ErrorHandler getErrorHandler() {
285285
return errorHandler;
286286
}
287287

288+
public void setErrorHandler(ErrorHandler handler) {
289+
this.errorHandler = handler;
290+
}
291+
288292
public CommandExecutor getCommandExecutor() {
289293
return executor;
290294
}

0 commit comments

Comments
 (0)