@@ -115,7 +115,7 @@ public Response throwIfResponseFailed(Response response, long duration) throws R
115
115
message = String .valueOf (e );
116
116
}
117
117
118
- Throwable serverError = rebuildServerError (rawErrorData );
118
+ Throwable serverError = rebuildServerError (rawErrorData , response . getStatus () );
119
119
120
120
// If serverError is null, then the server did not provide a className (only expected if
121
121
// the server is a Java process) or a stack trace. The lack of a className is OK, but
@@ -141,7 +141,7 @@ public Response throwIfResponseFailed(Response response, long duration) throws R
141
141
142
142
String duration1 = duration (duration );
143
143
144
- if (message != null && message .indexOf (duration1 ) == - 1 ) {
144
+ if (message != null && ! message .contains (duration1 )) {
145
145
message = message + duration1 ;
146
146
}
147
147
@@ -216,7 +216,7 @@ private <T extends Throwable> T createThrowable(
216
216
return null ;
217
217
}
218
218
219
- private Throwable rebuildServerError (Map <String , Object > rawErrorData ) {
219
+ private Throwable rebuildServerError (Map <String , Object > rawErrorData , int responseStatus ) {
220
220
221
221
if (!rawErrorData .containsKey (CLASS ) && !rawErrorData .containsKey (STACK_TRACE )) {
222
222
// Not enough information for us to try to rebuild an error.
@@ -225,24 +225,34 @@ private Throwable rebuildServerError(Map<String, Object> rawErrorData) {
225
225
226
226
Throwable toReturn = null ;
227
227
String message = (String ) rawErrorData .get (MESSAGE );
228
+ Class clazz = null ;
228
229
230
+ // First: allow Remote Driver to specify the Selenium Server internal exception
229
231
if (rawErrorData .containsKey (CLASS )) {
230
232
String className = (String ) rawErrorData .get (CLASS );
231
233
try {
232
- Class clazz = Class .forName (className );
233
- if (clazz .equals (UnhandledAlertException .class )) {
234
- toReturn = createUnhandledAlertException (rawErrorData );
235
- } else if (Throwable .class .isAssignableFrom (clazz )) {
236
- @ SuppressWarnings ({"unchecked" })
237
- Class <? extends Throwable > throwableType = (Class <? extends Throwable >) clazz ;
238
- toReturn = createThrowable (throwableType , new Class <?>[] {String .class },
239
- new Object [] {message });
240
- }
234
+ clazz = Class .forName (className );
241
235
} catch (ClassNotFoundException ignored ) {
242
236
// Ok, fall-through
243
237
}
244
238
}
245
239
240
+ // If the above fails, map Response Status to Exception class
241
+ if (null == clazz ) {
242
+ clazz = errorCodes .getExceptionType (responseStatus );
243
+ }
244
+
245
+ if (clazz .equals (UnhandledAlertException .class )) {
246
+ toReturn = createUnhandledAlertException (rawErrorData );
247
+ } else if (Throwable .class .isAssignableFrom (clazz )) {
248
+ @ SuppressWarnings ({"unchecked" })
249
+ Class <? extends Throwable > throwableType = (Class <? extends Throwable >) clazz ;
250
+ toReturn = createThrowable (
251
+ throwableType ,
252
+ new Class <?>[] {String .class },
253
+ new Object [] {message });
254
+ }
255
+
246
256
if (toReturn == null ) {
247
257
toReturn = new UnknownServerException (message );
248
258
}
0 commit comments