* Checks a legacy response from the Selenium 2.0 wire protocol for an error. * @param {*} responseObj the response object to check. * @return {*} responseObj the original response if it does not define an error. * @throws {WebDriverError} if the response object defines an error.
(responseObj)
| 539 | * @throws {WebDriverError} if the response object defines an error. |
| 540 | */ |
| 541 | function checkLegacyResponse(responseObj) { |
| 542 | // Handle the legacy Selenium error response format. |
| 543 | if (isObject(responseObj) && typeof responseObj.status === 'number' && responseObj.status !== 0) { |
| 544 | const { status, value } = responseObj |
| 545 | |
| 546 | let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError |
| 547 | |
| 548 | if (!value || typeof value !== 'object') { |
| 549 | throw new ctor(value + '') |
| 550 | } else { |
| 551 | let message = value['message'] + '' |
| 552 | if (ctor !== UnexpectedAlertOpenError) { |
| 553 | throw new ctor(message) |
| 554 | } |
| 555 | |
| 556 | let text = '' |
| 557 | if (value['alert'] && typeof value['alert']['text'] === 'string') { |
| 558 | text = value['alert']['text'] |
| 559 | } |
| 560 | throw new UnexpectedAlertOpenError(message, text) |
| 561 | } |
| 562 | } |
| 563 | return responseObj |
| 564 | } |
| 565 | |
| 566 | // PUBLIC API |
| 567 |