Return a custom response if connection to server failed

I’ve got a mitmproxy setup with multiple reverse proxy targets. Sometimes some of them timeout.
when that happens the client receives: “ProtocolException('Server connection to (‘domain.com’, 80) failed:”

Tried making a custom response, but it looks like mitmproxy just ignores it.

Instead of client receiving that message I want to make a custom response or show nothing.
I’ve tried killing the flow, like this:

def error(flow: mitmproxy.http.HTTPFlow):
flow.kill()

but the user still receives the same response.