Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions java/src/org/openqa/selenium/remote/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.openqa.selenium.remote;

import static java.util.Objects.requireNonNullElse;

import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.math.RoundingMode;
Expand Down Expand Up @@ -97,8 +99,9 @@ public Response throwIfResponseFailed(Response response, long duration) throws R
throw new RuntimeException(throwable);
}

int responseStatus = requireNonNullElse(response.getStatus(), -1);
Class<? extends WebDriverException> outerErrorType =
errorCodes.getExceptionType(response.getStatus());
errorCodes.getExceptionType(responseStatus);

Object value = response.getValue();
String message = null;
Expand All @@ -120,7 +123,7 @@ public Response throwIfResponseFailed(Response response, long duration) throws R
message = String.valueOf(e);
}

Throwable serverError = rebuildServerError(rawErrorData, response.getStatus());
Throwable serverError = rebuildServerError(rawErrorData, responseStatus);

// If serverError is null, then the server did not provide a className (only expected if
// the server is a Java process) or a stack trace. The lack of a className is OK, but
Expand Down
9 changes: 9 additions & 0 deletions java/test/org/openqa/selenium/remote/ErrorHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ void testShouldThrowAVanillaWebDriverExceptionIfServerDoesNotProvideAValue() {
.withMessageContaining(new WebDriverException().getMessage());
}

@Test
void testShouldThrowAVanillaWebDriverExceptionIfResponseStatusIsNull() {
Response response = new Response();
assertThatExceptionOfType(WebDriverException.class)
.isThrownBy(() -> handler.throwIfResponseFailed(response, 123))
.withNoCause()
.withMessageContaining(new WebDriverException().getMessage());
}

@Test
void testShouldNotSetCauseIfResponseValueIsJustAString() {
assertThatExceptionOfType(WebDriverException.class)
Expand Down
Loading