From 49dd88dbb7d53aa8af9c6dc8bc90fdf6fbbf2895 Mon Sep 17 00:00:00 2001
From: Pierre-antoine Comby <comby@crans.org>
Date: Thu, 26 Mar 2020 23:04:51 +0100
Subject: [PATCH] add errMsg function

---
 static/js/base.js   | 10 +++++++++-
 static/js/consos.js |  3 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/static/js/base.js b/static/js/base.js
index f7085850..d06c2fbe 100644
--- a/static/js/base.js
+++ b/static/js/base.js
@@ -28,7 +28,15 @@ function addMsg(msg, alert_type) {
         + msg + "</div>\n";
     msgDiv.html(html);
 }
-
+/**
+ * add Muliple error message from err_obj
+ * @param err_obj {error_code:erro_message}
+ */
+function errMsg(errs_obj){
+    for (const err_msg of Object.values(errs_obj)) {
+              addMsg(err_msg,'danger');
+          }
+}
 /**
  * Reload the balance of the user on the right top corner
  */
diff --git a/static/js/consos.js b/static/js/consos.js
index 896f996c..27173365 100644
--- a/static/js/consos.js
+++ b/static/js/consos.js
@@ -200,7 +200,6 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
             "template": template
         }, reset).fail(function (e) {
             reset();
-
-            addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
+            errMsg(e.responseJSON);
     });
 }
-- 
GitLab