diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-06-07 21:04:57 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-06-07 21:04:57 +0200 |
commit | 034e518f06163072ee69dcab8a6f0b776cdd161a (patch) | |
tree | 6cfb6d1ad9a7121174a26a47cc53903faf5c8336 | |
parent | ea4d0bd2cb6c2b61c2baa940e9dc5bc9c02ef9f5 (diff) | |
download | backoffice-034e518f06163072ee69dcab8a6f0b776cdd161a.tar.gz backoffice-034e518f06163072ee69dcab8a6f0b776cdd161a.tar.bz2 backoffice-034e518f06163072ee69dcab8a6f0b776cdd161a.zip |
Aggregate commit.
Fix the way alternative config files are read from
command line, and add a big "switch" where error codes
from HTTP services are read and rendered as nice-ish
messages.
-rw-r--r-- | js/backoffice.js | 73 | ||||
-rw-r--r-- | taler-merchant-backoffice.in | 3 | ||||
-rw-r--r-- | talerbackoffice/backoffice/backoffice.py | 2 |
3 files changed, 70 insertions, 8 deletions
diff --git a/js/backoffice.js b/js/backoffice.js index 187ebf5..4f11d54 100644 --- a/js/backoffice.js +++ b/js/backoffice.js @@ -60,6 +60,65 @@ var LAST = 0; var SCROLL = true; /** + * Maps error codes from https://git.taler.net/exchange.git/tree/src/include/taler_error_codes.h + * to friendlier messages. + */ +function error_map(code){ + switch (code){ + + /* /history errors. */ + case "2200": + return "The timestamp used to query the history overflowed."; + case "2201": + return "Merchant had serious problems in its history database"; + case "2202": + return "The instance used to query the history is unknown"; + + /* /track/order errors. */ + case "2307": + /* Such errors should provide full proof to the user. */ + return "One of the coin was untraceable"; + case "2308": + case "2408": + return "Conflicting reports from the Exchange"; + case "2301": + return "Instance is unknown to track this order"; + case "2303": + case "2304": + case "2305": + case "1801": + return "Merchant database failed, code:" + code; + case "2306": + return "One of the coin failed at getting its WTID"; + + /* /track/transfer errors. */ + case "2410": + return "Exchange charged a higher wire fee than what " + + " it was originally advertised."; + case "2405": + return "Error from the exchange, no proof received!"; + case "2404": + case "2402": + return "Database failure, could not store results: " + code; + case "2406": + return "Database failure, could not retrieve previous results"; + case "2407": + return "Database failure, internal logic error"; + case "2409": + return "Merchant could not pack the JSON response"; + case "2403": + return "Merchant failed to request /track/transfer to \ + the exchange"; + case "2400": + return "Exchange timed out.."; + + default: + return "Error code not given."; + } + +} + +/** * Convert Taler-compliant amount to human-friendly string. * The amount may be both a string or object type. */ @@ -212,25 +271,25 @@ var show_error = show_warning = function(response_text){ toggle_loader(); close_popup(); - var msg = response_text; + var msg; + var hint = ""; try{ var parse = JSON.parse(response_text); console.log("Response was at least JSON"); - if (parse['error']) - msg = parse['error']; + /* handles undefined codes too. */ + msg = error_map(parse['code']); - /* Give precedence to 'hint' as it is usually - * human-friendlier */ if (parse['hint']) - msg = parse['hint']; + hint = parse['hint']; } catch (e) { + msg = response_text; console.log("Must keep raw response"); } /* Get hold of the info bar. */ var info_bar = document.getElementById("information-bar"); - info_bar.innerHTML = `<p>${msg}</p>`; + info_bar.innerHTML = `<p>${msg} ${hint}</p>`; info_bar.style.visibility = "visible"; } diff --git a/taler-merchant-backoffice.in b/taler-merchant-backoffice.in index 0ea5097..eed11f3 100644 --- a/taler-merchant-backoffice.in +++ b/taler-merchant-backoffice.in @@ -19,12 +19,12 @@ site.addsitedir("%s/lib/python%d.%d/site-packages" % ( sys.version_info.minor)) LOGGER = logging.getLogger(__name__) -TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) # No perfect match to our logging format, but good enough ... UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" def handle_serve_http(args): + TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) port = args.port if port is None: port = TC["backoffice-%s" % args.frontend]["http_port"].value_int(required=True) @@ -39,6 +39,7 @@ def handle_serve_http(args): "--env", "BACKOFFICE_INSTANCES=%s" % TC["backoffice-%s" % args.frontend]["instances"].value_string(required=True)) def handle_serve_uwsgi(args): + TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) serve_uwsgi = TC["backoffice-%s" % args.frontend]["uwsgi_serve"].value_string(required=True).lower() params = ["uwsgi", "uwsgi", "--master", diff --git a/talerbackoffice/backoffice/backoffice.py b/talerbackoffice/backoffice/backoffice.py index 2ce66e6..65d76ce 100644 --- a/talerbackoffice/backoffice/backoffice.py +++ b/talerbackoffice/backoffice/backoffice.py @@ -45,6 +45,8 @@ INSTANCES = os.environ.get("BACKOFFICE_INSTANCES") CURRENCY = TC["taler"]["currency"].value_string(required=True) app.config.from_object(__name__) +print("My backend is: " + BACKEND_URL) + @app.context_processor def utility_processor(): |