Commit 4d84fa1d authored by Bertrand  NÉRON's avatar Bertrand NÉRON

diferentiate the response when data are invalid than where ceredntials invalid

when data are not valid a forbiden error is thrown and the message
was not clear.
know the 2 origin of erro data or credentials are treated separately and
an improved message is displayed to the user
parent f949a1e6
......@@ -211,7 +211,22 @@ def fill_db(server_uri, db_name, user, passwd, replicon_db, system_db, force_upd
g[field] = value
genes.append(g)
secretion_system.genes = genes
secreton_db.save_doc(secretion_system, force_update=force_update)
try:
secreton_db.save_doc(secretion_system, force_update=force_update)
except restkit.errors.Unauthorized as err:
import re
reason = re.search('"reason":"(.*)"}$', err.message)
if reason:
reason = reason.groups()[0]
else:
reason = ''
import json
raise RuntimeError("Invalid data: {0} \ndata = \n{1}".format(reason,
json.dumps(secretion_system.to_json(),
indent=4)
)
)
if __name__ == '__main__':
import argparse
......@@ -285,8 +300,9 @@ if __name__ == '__main__':
replicon_db, system_db, force_update=args.force_update)
break
except restkit.errors.Unauthorized as err:
try_again += 1
if try_again > 2:
sys.exit("Authentication failure")
except Exception as err:
sys.exit(2)
if err.status_int == 401:
try_again += 1
if try_again > 2:
sys.exit("Authentication failure")
else:
raise err
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment