gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant-frontends] branch master updated: Implement


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant-frontends] branch master updated: Implementing /track/order handler within blog. Implementing 202 "track not ready" error handler too.
Date: Mon, 27 Feb 2017 15:14:06 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository merchant-frontends.

The following commit(s) were added to refs/heads/master by this push:
     new e971210  Implementing /track/order handler within blog. Implementing 
202 "track not ready" error handler too.
e971210 is described below

commit e971210f812e798e9f9652377b55a6455bb6701e
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Feb 27 15:13:15 2017 +0100

    Implementing /track/order handler within blog.
    Implementing 202 "track not ready" error handler too.
---
 talerfrontends/blog/blog.py | 27 ++++++++++++++++++++++++++-
 talerfrontends/helpers.py   | 19 +++++++++----------
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/talerfrontends/blog/blog.py b/talerfrontends/blog/blog.py
index 3f0e745..cfd0ae3 100644
--- a/talerfrontends/blog/blog.py
+++ b/talerfrontends/blog/blog.py
@@ -35,7 +35,7 @@ from pprint import pprint
 from talerfrontends.talerconfig import TalerConfig
 from talerfrontends.helpers import (make_url, frontend_common,
         expect_parameter, expect_parameter_int, BackendError,
-        MalformedParameterError, join_urlparts)
+        MalformedParameterError, join_urlparts, TrackNotReadyError)
 from talerfrontends.blog.content import articles, get_article_file, 
get_image_file
 
 logger = logging.getLogger(__name__)
@@ -178,3 +178,28 @@ def track():
     # return minimal HTML+JavaScript for calling /history
     response = 
flask.make_response(flask.render_template("templates/backoffice.html"))
     return response
+
address@hidden("/track/order")
+def track_order():
+
+    instance = expect_parameter("instance")
+    order_id = expect_parameter("order_id")
+
+    url = urljoin(BACKEND_URL, 'track/transaction')
+    params = {'order_id': order_id, 'instance': instance}
+    r = requests.get(url, params)
+
+    if r.status_code not in [200, 202, 424]:
+        logger.error("failed to GET to '%s'", url)
+        raise BackendError(r.status_code, r.text)
+    obj = r.json()
+    if 202 == r.status_code:
+        raise TrackNotReadyError(r.status_code, obj["code"], order_id)
+    if 404 == r.status_code:
+        raise CustomError(r.code, "Unknown order_id", s.status_code)
+    if 424 == r.status_code:
+        raise TrackTransactionConflictError(r.status_code, order_id, r.text)
+    else:
+        raise BackendError(r.status_code, r.text)
+
+    return obj
diff --git a/talerfrontends/helpers.py b/talerfrontends/helpers.py
index 43056cd..9d3dc14 100644
--- a/talerfrontends/helpers.py
+++ b/talerfrontends/helpers.py
@@ -183,9 +183,10 @@ class BackendError(Exception):
         super().__init__(status, response)
 
 class TrackNotReadyError(Exception):
-    def __init__(self, status, transaction_id):
+    def __init__(self, status, error_code, order_id):
         self.status = status
-        self.transaction_id = transaction_id
+        self.order_id = order_id
+        self.error_code = error_code
         super().__init__(status, 'Track not ready')
 
 class TrackTransactionConflictError(Exception):
@@ -281,12 +282,10 @@ def track_transaction(tid, instance):
         raise TrackNotReadyError(r.status_code, tid)
     if 404 == r.status_code:
         raise CustomError(r.code, "Unknown transaction supplied", 
s.status_code)
-    if r.status_code == 424:
-        error_code = json.loads(r.text)['code']
-        if TRACK_TRANSACTION_CONFLICT == error_code:
-            raise TrackTransactionConflictError(r.status_code, tid, r.text)
-        else:
-            raise CustomError(error_code, r.details, r.status_code)
+    if 424 == r.status_code:
+        raise TrackTransactionConflictError(r.status_code, tid, r.text)
+    else:
+        raise BackendError(r.status_code, r.text)
     track = r.json()
     return track
 
@@ -349,10 +348,10 @@ def handle_custom_error(error):
 
 @frontend_common.app_errorhandler(TrackNotReadyError)
 def handle_track_not_ready_error(error):
-    logger.warn("Transaction %d has still not been transferred" % 
error.transaction_id)
+    logger.warn("Order %s has not been transferred yet" % error.order_id)
     return make_response(render_template("error.html",
                                          error = error.error_code,
-                                         details = "Transaction %d is still 
waiting for being transferred" % error.transaction_id))
+                                         details = "Order %s is still waiting 
for being paid back" % error.order_id))
 
 @frontend_common.app_errorhandler(TrackTransactionConflictError)
 def handle_track_transaction_conflict_error(error):

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]