client-barcode: Add some network error handling
This commit is contained in:
parent
f3c86688a7
commit
c70ec751b1
|
@ -12,6 +12,7 @@ import sys
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import urllib2
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
|
@ -100,27 +101,36 @@ class Status:
|
||||||
|
|
||||||
def login(self, auth_blob):
|
def login(self, auth_blob):
|
||||||
assert(not self.logged_in())
|
assert(not self.logged_in())
|
||||||
|
|
||||||
user_name = net.get_user_name_from_auth_blob(auth_blob)
|
user_name = net.get_user_name_from_auth_blob(auth_blob)
|
||||||
|
balance = net.get_balance(user_name)
|
||||||
|
|
||||||
self.auth_blob = auth_blob
|
self.auth_blob = auth_blob
|
||||||
self.login_name = user_name
|
self.login_name = user_name
|
||||||
self.balance = net.get_balance(user_name)
|
self.balance = balance
|
||||||
self.transfers = list()
|
self.transfers = list()
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
assert(self.logged_in())
|
assert(self.logged_in())
|
||||||
|
|
||||||
# Process command queue
|
# Process command queue
|
||||||
for (command, balance_backup) in self.transfers:
|
for (command, balance_backup) in list(self.transfers):
|
||||||
command.run(self.login_name)
|
try:
|
||||||
self.transfers = None
|
command.run(self.login_name)
|
||||||
|
except urllib2.HTTPError as e:
|
||||||
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.transfers.pop(0)
|
||||||
|
|
||||||
# Show final balance for some time
|
if not self.transfers:
|
||||||
clear()
|
# Show final balance for some time
|
||||||
self.dump()
|
clear()
|
||||||
delay('Logout', 3)
|
self.dump()
|
||||||
|
delay('Logout', 3)
|
||||||
|
|
||||||
# Logout
|
# Logout
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
def find(self, item_id):
|
def find(self, item_id):
|
||||||
try:
|
try:
|
||||||
|
@ -171,12 +181,18 @@ def handle(line, status):
|
||||||
item_id = int(line) # TODO
|
item_id = int(line) # TODO
|
||||||
try:
|
try:
|
||||||
item = status.find(item_id)
|
item = status.find(item_id)
|
||||||
except: # TODO
|
except urllib2.HTTPError as e:
|
||||||
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)
|
if e.code == 404: # URL not found == item not found with REST
|
||||||
|
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)
|
||||||
|
else:
|
||||||
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||||
else:
|
else:
|
||||||
status.buy(item)
|
status.buy(item)
|
||||||
else:
|
else:
|
||||||
status.login(line)
|
try:
|
||||||
|
status.login(line)
|
||||||
|
except urllib2.URLError as e:
|
||||||
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % e.reason)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue