## 🐛 Bug Report

**Description**

The error returned by the Selenium server is not in the expected format (JSON) under certain conditions.

Specifically, if a session has expired due to the browser session timeout being exceeded, and a remote client attempts an operation on the session, a plain text response may be returned like this:

`JSON::ParserError: 809: unexpected token at 'Unable to route (POST) /session/a4d35ecd4906f0ef90ad915764adb7c2/url'`

The message will vary depending on the client's request--it may be any of GET/POST/DELETE

## To Reproduce

https://gist.github.com/zetetic/82766452f77b864d577aab67221d749e

See the README for instructions. There are two examples using RSpec that produce a correct response, wait until the browser timeout has been triggered, and then produce the error response.

## Expected behavior

Client requests against the server HTTP endpoint should return JSON formatted responses.

## Test script or set of commands reproducing this issue

see above

## Environment

OS: Linux
Browser: Chrome
Browser version: 93.0.4577.63
Browser Driver version: ChromeDriver 93.0.4577.15 
Language Bindings version: Ruby 4.0.0.rc1
Selenium Grid version (if applicable): Selenium Standalone 4.0.0-rc-2 (revision db2bb9ed96)

Require.nonNull("Client config", config);
    URI url = config.baseUri();
    if (self.getProtocol().equals(url.getScheme()) &&
      self.getHost().equals(url.getHost()) &&
      self.getPort() == url.getPort()) {
      return new HttpClient() {
        @Override
        public HttpResponse execute(HttpRequest request) throws UncheckedIOException {
          HttpResponse response = new HttpResponse();
          if (!handler.test(request)) {
            response.setStatus(404);
            response.setContent(utf8String("Unable to route " + request));
            return response;
          }
          return handler.execute(request);
        }
        @Override
        public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
          throw new UnsupportedOperationException("openSocket");
        }
      };
    }
    return delegate.createClient(config);
  }
  @Override
  public void cleanupIdleClients() {
    delegate.cleanupIdleClients();
  }
}