Fix some bugs

- Fix a bug that `GET` requests without data will report an error in API
- Fix a bug that `aggregate` requests will get an error when the inner function raises an error
- Fix a bug that the charts of a course cannot be the same because of the incorrect primary keys
- Fix a bug that global ranking scores cannot be calculated if there are no chart in the database #61
- The first try to fix #60 (I don't think it can be done so easily.)
This commit is contained in:
Lost-MSth
2022-07-20 21:59:26 +08:00
parent 47f05cdf1e
commit 93f4ad4999
7 changed files with 25 additions and 24 deletions

View File

@@ -82,16 +82,19 @@ def aggregate():
{key: value[0] for key, value in parse_qs(urlparse(endpoint).query).items()})
resp_t = map_dict[urlparse(endpoint).path]()
if isinstance(resp_t, tuple):
# The response may be a tuple, if it is an error response
resp_t = resp_t[0]
if hasattr(resp_t, "response"):
resp_t = resp_t.response[0].decode().rstrip('\n')
resp = json.loads(resp_t)
if hasattr(resp, 'get') and resp.get('success') is False:
finally_response = {'success': False, 'error_code': 7, 'extra': {
"id": i['id'], 'error_code': resp.get('error_code')}}
finally_response = {'success': False, 'error_code': resp.get(
'error_code'), 'id': i['id']}
if "extra" in resp:
finally_response['extra']['extra'] = resp['extra']
finally_response['extra'] = resp['extra']
#request = request_
return jsonify(finally_response)