Java 类org.openqa.selenium.remote.BeanToJsonConverter 实例源码

项目:grid-refactor-remote-server    文件:Responses.java   
/**
 * Creates a response object for a failed command execution.
 *
 * @param sessionId ID of the session that executed the command.
 * @param reason the failure reason.
 * @param screenshot a base64 png screenshot to include with the failure.
 * @return the new response object.
 */
public static Response failure(
    SessionId sessionId, Throwable reason, Optional<String> screenshot) {
  Response response = new Response();
  response.setSessionId(sessionId != null ? sessionId.toString() : null);
  response.setStatus(ERROR_CODES.toStatusCode(reason));
  response.setState(ERROR_CODES.toState(response.getStatus()));

  if (reason != null) {
    JsonObject json = new BeanToJsonConverter().convertObject(reason).getAsJsonObject();
    json.addProperty("screen", screenshot.orNull());
    response.setValue(json);
  }
  return response;
}