mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Support more complex errors (be able to return additional data in a json structure)
This commit is contained in:
parent
fe888dd841
commit
bfecb8b7dc
2 changed files with 14 additions and 2 deletions
|
@ -930,7 +930,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
|
||||||
raise YunohostError(failure_message_with_debug_instructions, raw_msg=True)
|
raise YunohostError(failure_message_with_debug_instructions, raw_msg=True, log_ref=operation_logger.name)
|
||||||
|
|
||||||
# Clean hooks and add new ones
|
# Clean hooks and add new ones
|
||||||
hook_remove(app_instance_name)
|
hook_remove(app_instance_name)
|
||||||
|
|
|
@ -32,11 +32,23 @@ class YunohostError(MoulinetteError):
|
||||||
are translated via m18n.n (namespace) instead of m18n.g (global?)
|
are translated via m18n.n (namespace) instead of m18n.g (global?)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, key, raw_msg=False, *args, **kwargs):
|
def __init__(self, key, raw_msg=False, log_ref=None, *args, **kwargs):
|
||||||
self.key = key # Saving the key is useful for unit testing
|
self.key = key # Saving the key is useful for unit testing
|
||||||
self.kwargs = kwargs # Saving the key is useful for unit testing
|
self.kwargs = kwargs # Saving the key is useful for unit testing
|
||||||
|
self.log_ref = log_ref
|
||||||
if raw_msg:
|
if raw_msg:
|
||||||
msg = key
|
msg = key
|
||||||
else:
|
else:
|
||||||
msg = m18n.n(key, *args, **kwargs)
|
msg = m18n.n(key, *args, **kwargs)
|
||||||
|
|
||||||
super(YunohostError, self).__init__(msg, raw_msg=True)
|
super(YunohostError, self).__init__(msg, raw_msg=True)
|
||||||
|
|
||||||
|
def content(self):
|
||||||
|
|
||||||
|
if not self.log_ref:
|
||||||
|
return super(YunohostError, self).content()
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"error": self.strerror,
|
||||||
|
"log_ref": self.log_ref
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue