getExceptionFromJsonWireResponse function Null safety

WebDriverException getExceptionFromJsonWireResponse(
  1. {int? httpStatusCode,
  2. String? httpReasonPhrase,
  3. dynamic jsonResp}
)

Temporary method to emulate the original json wire exception parsing logic.

Implementation

WebDriverException getExceptionFromJsonWireResponse(
    {int? httpStatusCode, String? httpReasonPhrase, dynamic jsonResp}) {
  if (jsonResp is Map) {
    var status = jsonResp['status'] as int?;
    var message = jsonResp['value']['message'] as String?;

    switch (status) {
      case 0:
        throw StateError('Not a WebDriverError Status: 0 Message: $message');
      case 6: // NoSuchDriver
        return NoSuchDriverException(status, message);
      case 7: // NoSuchElement
        return NoSuchElementException(status, message);
      case 8: // NoSuchFrame
        return NoSuchFrameException(status, message);
      case 9: // UnknownCommand
        return UnknownCommandException(status, message);
      case 10: // StaleElementReferenceException
        return StaleElementReferenceException(status, message);
      case 11: // ElementNotVisible
        return ElementNotVisibleException(status, message);
      case 12: // InvalidElementState
        return InvalidElementStateException(status, message);
      case 15: // ElementIsNotSelectable
        return ElementIsNotSelectableException(status, message);
      case 17: // JavaScriptError
        return JavaScriptException(status, message);
      case 19: // XPathLookupError
        return XPathLookupException(status, message);
      case 21: // Timeout
        return TimeoutException(status, message);
      case 23: // NoSuchWindow
        return NoSuchWindowException(status, message);
      case 24: // InvalidCookieDomain
        return InvalidCookieDomainException(status, message);
      case 25: // UnableToSetCookie
        return UnableToSetCookieException(status, message);
      case 26: // UnexpectedAlertOpen
        return UnexpectedAlertOpenException(status, message);
      case 27: // NoSuchAlert
        return NoSuchAlertException(status, message);
      case 28: // ScriptTimeout
        return ScriptTimeoutException(status, message);
      case 29: // InvalidElementCoordinates
        return InvalidElementCoordinatesException(status, message);
      case 30: // IMENotAvailable
        return IMENotAvailableException(status, message);
      case 31: // IMEEngineActivationFailed
        return IMEEngineActivationFailedException(status, message);
      case 32: // InvalidSelector
        return InvalidSelectorException(status, message);
      case 33: // SessionNotCreatedException
        return SessionNotCreatedException(status, message);
      case 34: // MoveTargetOutOfBounds
        return MoveTargetOutOfBoundsException(status, message);
      case 13: // UnknownError
      default: // new error?
        return UnknownException(status, message);
    }
  }
  if (jsonResp != null) {
    return InvalidRequestException(httpStatusCode, jsonResp as String);
  }
  return InvalidRequestException(httpStatusCode, httpReasonPhrase);
}