better handling of errors in redeems situations
short circuit execution that doesnt take away points + better message
This commit is contained in:
parent
c978b27799
commit
b666211142
|
@ -159,9 +159,11 @@ def add_to_counter(db, counter_name):
|
|||
(counter_name,)
|
||||
)
|
||||
db.commit()
|
||||
return True
|
||||
except Error as e:
|
||||
current_app.logger.error("Error occured adding to counter:", e.args[0])
|
||||
current_app.logger.error("To counter:", counter_name)
|
||||
return False
|
||||
|
||||
|
||||
def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
||||
|
@ -171,10 +173,12 @@ def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
|||
(redeem_name, user_id, note)
|
||||
)
|
||||
db.commit()
|
||||
return True
|
||||
except Error as e:
|
||||
current_app.logger.error("Error occured adding to redeem queue:", e.args[0])
|
||||
current_app.logger.error("To user:", user_id, " with redeem:",
|
||||
redeem_name, "with note:", note)
|
||||
return False
|
||||
|
||||
|
||||
def all_counters(db):
|
||||
|
|
|
@ -26,19 +26,22 @@ def handle_redeem(message, user_id):
|
|||
return
|
||||
|
||||
if redeem_type == "counter":
|
||||
add_to_counter(db, redeem)
|
||||
use_points(db, user_id, price)
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
if add_to_counter(db, redeem) and use_points(db, user_id, price):
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
else:
|
||||
send_chat(f"Redeeming {redeem} failed.")
|
||||
elif redeem_type == "list":
|
||||
add_to_redeem_queue(db, user_id, redeem)
|
||||
use_points(db, user_id, price)
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
if add_to_redeem_queue(db, user_id, redeem) and use_points(db, user_id, price):
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
else:
|
||||
send_chat(f"Redeeming {redeem} failed.")
|
||||
elif redeem_type == "note":
|
||||
if not note:
|
||||
send_chat(f"Cannot redeem {redeem}, no note included.")
|
||||
return
|
||||
add_to_redeem_queue(db, user_id, redeem, note)
|
||||
use_points(db, user_id, price)
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
if add_to_redeem_queue(db, user_id, redeem, note) and use_points(db, user_id, price):
|
||||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
else:
|
||||
send_chat(f"Redeeming {redeem} failed.")
|
||||
else:
|
||||
send_chat(f"{redeem} not redeemed because of an error.")
|
||||
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
||||
|
|
Loading…
Reference in New Issue