mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] Catch exceptions and return code in api function helper
This commit is contained in:
parent
f4853f2f4f
commit
f3dff47240
1 changed files with 21 additions and 7 deletions
|
@ -87,12 +87,26 @@ def api(namespaces, host='localhost', port=80, routes={},
|
|||
instead of using the cached one
|
||||
|
||||
"""
|
||||
moulinette = init_interface('api',
|
||||
kwargs={ 'routes': routes,
|
||||
'use_websocket': use_websocket },
|
||||
actionsmap={ 'namespaces': namespaces,
|
||||
'use_cache': use_cache })
|
||||
moulinette.run(host, port)
|
||||
try:
|
||||
moulinette = init_interface('api',
|
||||
kwargs={
|
||||
'routes': routes,
|
||||
'use_websocket': use_websocket
|
||||
},
|
||||
actionsmap={
|
||||
'namespaces': namespaces,
|
||||
'use_cache': use_cache
|
||||
}
|
||||
)
|
||||
moulinette.run(host, port)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
logging.getLogger('moulinette').error(e.strerror)
|
||||
return e.errno
|
||||
except KeyboardInterrupt:
|
||||
import logging
|
||||
logging.getLogger('moulinette').info(m18n.g('operation_interrupted'))
|
||||
return 0
|
||||
|
||||
def cli(namespaces, args, use_cache=True, output_as=None, parser_kwargs={}):
|
||||
"""Command line interface
|
||||
|
@ -122,6 +136,6 @@ def cli(namespaces, args, use_cache=True, output_as=None, parser_kwargs={}):
|
|||
moulinette.run(args, output_as=output_as)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
logging.getLogger('yunohost').error(e.strerror)
|
||||
logging.getLogger('moulinette').error(e.strerror)
|
||||
return e.errno
|
||||
return 0
|
||||
|
|
Loading…
Reference in a new issue