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
|
instead of using the cached one
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
moulinette = init_interface('api',
|
moulinette = init_interface('api',
|
||||||
kwargs={ 'routes': routes,
|
kwargs={
|
||||||
'use_websocket': use_websocket },
|
'routes': routes,
|
||||||
actionsmap={ 'namespaces': namespaces,
|
'use_websocket': use_websocket
|
||||||
'use_cache': use_cache })
|
},
|
||||||
|
actionsmap={
|
||||||
|
'namespaces': namespaces,
|
||||||
|
'use_cache': use_cache
|
||||||
|
}
|
||||||
|
)
|
||||||
moulinette.run(host, port)
|
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={}):
|
def cli(namespaces, args, use_cache=True, output_as=None, parser_kwargs={}):
|
||||||
"""Command line interface
|
"""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)
|
moulinette.run(args, output_as=output_as)
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger('yunohost').error(e.strerror)
|
logging.getLogger('moulinette').error(e.strerror)
|
||||||
return e.errno
|
return e.errno
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue