From 58baf9533b9f022f9247e96764101c132cd6fad5 Mon Sep 17 00:00:00 2001 From: CapableWeb <112625454+CapableWeb@users.noreply.github.com> Date: Fri, 16 Sep 2022 13:33:42 +0200 Subject: [PATCH] Make API return error before raising error again (#606) This change makes it so any API clients can show the same error as what happens in the terminal where you run the API. Useful for various WebUIs to display more helpful error messages to users. Co-authored-by: CapableWeb --- ldm/dream/server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ldm/dream/server.py b/ldm/dream/server.py index b56e21f6c7..002d630326 100644 --- a/ldm/dream/server.py +++ b/ldm/dream/server.py @@ -247,6 +247,15 @@ class DreamServer(BaseHTTPRequestHandler): except CanceledException: print(f"Canceled.") return + except Exception as e: + print("Error happened") + print(e) + self.wfile.write(bytes(json.dumps( + {'event': 'error', + 'message': str(e), + 'type': e.__class__.__name__} + ) + '\n',"utf-8")) + raise e class ThreadingDreamServer(ThreadingHTTPServer):