def send_error(self, status_code, **kwargs):
        """event stream cannot set an error code, so send an error event"""
        exc_info = kwargs.get("exc_info")
        message = ""
        if exc_info:
            message = self.extract_message(exc_info)
        if not message:
            message = responses.get(status_code, "Unknown HTTP Error")

        # this cannot be async
        evt = json.dumps(
            {
                "phase": "failed",
                "status_code": status_code,
                "message": message + "\n",
            }
        )
        self.write(f"data: {evt}\n\n")
        self.finish()
event stream cannot set an error code, so send an error event
binderhub/builder.py