Repository navigation
Conversation
MobileErrorHandler only raised when the response body was a W3C error object and returned silently otherwise, regardless of the HTTP status. So an HTML or plain-text error page from a proxy or load balancer, or a 401, was handed back to the caller as the command result: find_element() returned the HTML string of a 502 page, page_source returned 'Authorization Required' and click() silently "succeeded". The handler also looked for an error object in successful responses, so a 200 response whose script result contained value.error raised a WebDriverException. Return early for successful responses, as Selenium's ErrorHandler does, and raise a WebDriverException with the response body when an error response is not a W3C error object. W3C errors are mapped to exception classes as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MattL1989
force-pushed
the
fix/error-handler-http-status
branch
from
November 1, 2026 18:50
41a453f to
9235c91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MobileErrorHandler.check_responseonly raised when the response body was a W3C error object, and returned silently in every other case, whatever the HTTP status. Selenium'sRemoteConnectionhands HTTP errors to the handler as{'status': <http status>, 'value': <body>}. So when a proxy, load balancer or device farm gateway in front of Appium answers with an error page, the error page itself came back to the caller as the command result:POST /element→ 502 with an HTML pagefind_element()returns the HTML string, although it is annotated to return aWebElementGET /source→ 401driver.page_sourcereturns'Authorization Required'POST /element/{id}/click→ 500Internal Server Error(text/plain)click()returns normallyThe reverse also happened. A successful 200 response whose result merely looked like an error raised
WebDriverException: ok: for example,execute_scriptreturning{'value': {'error': 'none', 'message': 'ok'}}.Selenium's own
ErrorHandlerraises in the first three cases and passes the last one.Fix
ErrorCode.SUCCESS, exactly as Selenium'sErrorHandlerdoes.WebDriverExceptionwith the body as the message: for exampleMessage: <html><body>502 Bad Gateway</body></html>. I raise it directly rather than calling Selenium'sErrorHandler, because Selenium's handler crashes withAttributeErroron some non-standard bodies, such as a JSON list.NoSuchContextExceptionandInvalidSwitchToTargetException.Behaviour change: error responses that are not W3C error objects now raise instead of being returned as a value.
Tests
test/unit/webdriver/errorhandler_test.pychecks that the handler:no such elementerror toNoSuchElementException;value.error;find_element()hits a 502 page, checked end to end through httpretty.ruff check,ruff format --check,mypy appiumand the full unit test suite pass.Generated by Claude Code