## 🐛 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)

package org.openqa.selenium.grid.web;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.WebSocket;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URL;
import static org.openqa.selenium.remote.http.Contents.utf8String;
public class RoutableHttpClientFactory implements HttpClient.Factory {
  private final URL self;
  private final CombinedHandler handler;
  private final HttpClient.Factory delegate;
  public RoutableHttpClientFactory(URL self, CombinedHandler handler, HttpClient.Factory delegate) {
    this.self = Require.nonNull("URL", self);
    this.handler = Require.nonNull("Handler", handler);
    this.delegate = Require.nonNull("Delegate", delegate);
  }
  @Override
  public HttpClient createClient(ClientConfig config) {