Skip to content

Commit

Permalink
IMPROVE handling of communication with app server in case of HTTP errors
Browse files Browse the repository at this point in the history
 * recognize HTTP errors and return False in MobileAppCartModel.load()
 * ADD debug messages to JSONDecodeError and RequestError
 * improve comment on function
 * relevant to #17
  • Loading branch information
patkan authored and mgmax committed Jul 15, 2015
1 parent 86e1df4 commit de3ca6c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions FabLabKasse/shopping/cart_from_app/cart_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,34 @@ def load(self):
been uploaded yet for the current id or if an error occured
:return: list of tuples (product_code, quantity) or False
:rtype: list[(int, Decimal)] | bool
:raise: None (hopefully) - just returns False in normal cases of error
If the cart id seems already used, the random cart id is updated. please connect to the cart_id_changed() signal and update the shown QR code.
If the cart id seems already used, the random cart id is updated. please connect to the cart_id_changed() signal
and update the shown QR code.
"""
if self.cart_id == None:
self.generate_random_id()
return False
try:
req = requests.get(self.server_url + self.cart_id, timeout=self.timeout) # , HTTPAdapter(max_retries=5))
# TODO retries
except requests.exceptions.RequestException:
req.raise_for_status()
except requests.exceptions.HTTPError, exc:
logging.debug(u"app-checkout: app server responded with HTTP error {}".format(exc))
return False
except requests.exceptions.RequestException, exc:
logging.debug(u"app-checkout: general error in HTTP request: {}".format(exc))
return False
if req.text == "":
# logging.debug("app-checkout: empty response from server")
# no logging here since this is a standard use-case
return False
try:
data = req.json()
except simplejson.JSONDecodeError:
logging.debug("app-checkout: JSONDecodeError")
return False
logging.debug(u"received cart: {}".format(repr(data)))
if data["status"] != "PENDING":
Expand Down

0 comments on commit de3ca6c

Please sign in to comment.