getExceptionFromW3cResponse function

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

Temporary method to emulate the original w3c exception parsing logic.

Implementation

WebDriverException getExceptionFromW3cResponse(
    {int httpStatusCode, String httpReasonPhrase, dynamic jsonResp}) {
  if (jsonResp is Map && jsonResp.keys.contains('value')) {
    final value = jsonResp['value'];

    switch (value['error']) {
      case 'invalid argument':
        return InvalidArgumentException(httpStatusCode, value['message']);
      case 'no such element':
        return NoSuchElementException(httpStatusCode, value['message']);
      default:
        return WebDriverException(httpStatusCode, value['message']);
    }
  }

  return InvalidResponseException(httpStatusCode, jsonResp.toString());
}