mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
pack logging into custom error processing
This commit is contained in:
parent
008917fdef
commit
e925095503
@ -24,10 +24,18 @@ class IntegrationPluginError(Exception):
|
|||||||
return self.message
|
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
|
package_path = traceback.extract_tb(error.__traceback__)[-1].filename
|
||||||
install_path = sysconfig.get_paths()["purelib"]
|
install_path = sysconfig.get_paths()["purelib"]
|
||||||
package_name = pathlib.Path(package_path).relative_to(install_path).parts[0]
|
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:
|
if do_raise:
|
||||||
raise IntegrationPluginError(package_name, str(error))
|
raise IntegrationPluginError(package_name, str(error))
|
||||||
|
|
||||||
return package_name, str(error)
|
return package_name, str(error)
|
||||||
|
Loading…
Reference in New Issue
Block a user