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 (‘’, 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):

but the user still receives the same response.