How do I catch this error?

[2023-06-29 14:49:38 +0800] [2313338] [ERROR] protocol.connection_task uncaught
Traceback (most recent call last):
  File "/venv/lib/python3.10/site-packages/sanic/request.py", line 152, in __init__
    self._parsed_url = parse_url(url_bytes)
  File "httptools/parser/url_parser.pyx", line 105, in httptools.parser.url_parser.parse_url
httptools.parser.errors.HttpParserInvalidURLError: invalid url b'google.com:443'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/venv/lib/python3.10/site-packages/sanic/http/http1.py", line 123, in http1
    await self.http1_request_header()
  File "http1_request_header", line 65, in http1_request_header
    "stage",
  File "/venv/lib/python3.10/site-packages/sanic/request.py", line 154, in __init__
    raise BadURL(f"Bad URL: {url_bytes.decode()}")
sanic.exceptions.BadURL: Bad URL: google.com:443

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/venv/lib/python3.10/site-packages/sanic/request.py", line 152, in __init__
    self._parsed_url = parse_url(url_bytes)
  File "httptools/parser/url_parser.pyx", line 105, in httptools.parser.url_parser.parse_url
httptools.parser.errors.HttpParserInvalidURLError: invalid url b'google.com:443'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "connection_task", line 15, in connection_task
    from asyncio import CancelledError
  File "/venv/lib/python3.10/site-packages/sanic/http/http1.py", line 153, in http1
    await self.error_response(e)
  File "/venv/lib/python3.10/site-packages/sanic/http/http1.py", line 429, in error_response
    self.create_empty_request()
  File "/venv/lib/python3.10/site-packages/sanic/http/http1.py", line 447, in create_empty_request
    self.request = self.protocol.request_class(
  File "/venv/lib/python3.10/site-packages/sanic/request.py", line 154, in __init__
    raise BadURL(f"Bad URL: {url_bytes.decode()}")
sanic.exceptions.BadURL: Bad URL: google.com:443

The client requests something like GET google.com:443 HTTP/1.1 and is probably some automated crawler on a search for servers to exploit. So, with Sanic having rejected the erroneous request, you don’t really need to do more.

But that message is indeed long and ugly, and instead should result in a BadRequest response to client. We’ll have to look at that, to get those exceptions handled the normal way.