From e925095503de4074a2ea883d864100f92f7a8401 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 13:26:37 +0100 Subject: [PATCH] pack logging into custom error processing --- InvenTree/plugin/helpers.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index 3c1edd82fd..a832f5d92f 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -24,10 +24,18 @@ class IntegrationPluginError(Exception): return self.message -def get_plugin_error(error, do_raise: bool = False): +def get_plugin_error(error, do_raise: bool = False, do_log: bool = False, log_name: str = ''): package_path = traceback.extract_tb(error.__traceback__)[-1].filename install_path = sysconfig.get_paths()["purelib"] package_name = pathlib.Path(package_path).relative_to(install_path).parts[0] + + if do_log: + log_kwargs = {} + if log_name: + log_kwargs['reference'] = log_name + log_plugin_error({package_name: str(error)}, **log_kwargs) + if do_raise: raise IntegrationPluginError(package_name, str(error)) + return package_name, str(error)