From 924fd7825e3e43d53daeb7c33e7ff1d7816bc223 Mon Sep 17 00:00:00 2001 From: axolotle Date: Wed, 8 Nov 2023 19:11:18 +0100 Subject: [PATCH] cors: fix some http response error not being catched by cors decorator --- moulinette/interfaces/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 9c17ca17..20c9ec11 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -734,7 +734,11 @@ class Interface: def cors(callback): def wrapper(*args, **kwargs): - r = callback(*args, **kwargs) + try: + r = callback(*args, **kwargs) + except HTTPResponse as e: + r = e + origin = request.headers.environ.get("HTTP_ORIGIN", "") if origin and origin in self.allowed_cors_origins: resp = r if isinstance(r, HTTPResponse) else response