'Python Server-Sent-Events won't send Exception Response in Flask endpoint

I'm working on a Flask endpoint which will respond mimetype=text/event-stream. When I'm raising exception for a condition... the error response for that exception is never sent. Instead it returns 200 after I close the connection:

function:

def get_ds_updates(request_id):
try:
    msg = consume_rabbitmq_messages(request_id)

    if msg is False:
        raise EmptyQueueException("No Message found")

    return Response(msg, mimetype='text/event-stream')
except EmptyQueueException as e:
    return Response(str(e)), GATEWAY_TIMEOUT
except Exception as e:
    return Response(str(e)), INTERNAL_SERVER_ERROR

Can someone point out the issue with my code? Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source