Skip to content
Snippets Groups Projects
Commit 4d84fa1d authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

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
No related branches found
No related tags found
No related merge requests found
...@@ -211,7 +211,22 @@ def fill_db(server_uri, db_name, user, passwd, replicon_db, system_db, force_upd ...@@ -211,7 +211,22 @@ def fill_db(server_uri, db_name, user, passwd, replicon_db, system_db, force_upd
g[field] = value g[field] = value
genes.append(g) genes.append(g)
secretion_system.genes = genes 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__': if __name__ == '__main__':
import argparse import argparse
...@@ -285,8 +300,9 @@ if __name__ == '__main__': ...@@ -285,8 +300,9 @@ if __name__ == '__main__':
replicon_db, system_db, force_update=args.force_update) replicon_db, system_db, force_update=args.force_update)
break break
except restkit.errors.Unauthorized as err: except restkit.errors.Unauthorized as err:
try_again += 1 if err.status_int == 401:
if try_again > 2: try_again += 1
sys.exit("Authentication failure") if try_again > 2:
except Exception as err: sys.exit("Authentication failure")
sys.exit(2) else:
raise err
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