kavezo / ZipZap

48 stars 16 forks source link

Quick fix for 500 errors on story quests #42

Closed EmpressFiona closed 3 years ago

EmpressFiona commented 3 years ago

For whatever reason, playing story quests sometimes causes a problem where the variable apAmount isn't initialized in api/questEndpoints/get.py. Because the spendAP function has no fallback, the server returns a 500 error because the apAmount function fails due to an uninitialized variable:

 2020-12-20 18:14:59,527 INFO app : {'userQuestBattleResultId': '24ee9484-42ef-11eb-aaf2-95a62cf39bc7'}
2020-12-20 18:14:59,540 ERROR app : Exception on /quest/native/get [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/ZipZap/api/quest.py", line 32, in handleQuest
    return get()
  File "/ZipZap/api/questEndpoints/get.py", line 505, in get
    apStatus = spendAP(battle)
  File "/ZipZap/api/questEndpoints/get.py", line 447, in spendAP
    apStatus['point'] -= apAmount
UnboundLocalError: local variable 'apAmount' referenced before assignment
2020-12-20 18:14:59,541 INFO app : None 

This is a quick fix for that which makes the apAmount variable initialize as 1 if all other conditions fail. I don't know why these conditions fail in the first place, but this ensures it doesn't prevent the quest from being activated. (More testing would be required to figure out why this happened in the first place.)