add some sense of api error handling on web server
This commit is contained in:
parent
4c4a747e16
commit
0e2aef1941
@ -96,6 +96,9 @@ class Db:
|
|||||||
'grant_type': 'refresh_token',
|
'grant_type': 'refresh_token',
|
||||||
'refresh_token': refresh_token,
|
'refresh_token': refresh_token,
|
||||||
})
|
})
|
||||||
|
if res.status_code != 200:
|
||||||
|
return None
|
||||||
|
|
||||||
print(res.status_code)
|
print(res.status_code)
|
||||||
print(res.content)
|
print(res.content)
|
||||||
res = res.json()
|
res = res.json()
|
||||||
|
@ -93,11 +93,15 @@ def index():
|
|||||||
'description': f"{count}{counttype}"
|
'description': f"{count}{counttype}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
resp = create_rq.json()
|
resp = create_rq.json()
|
||||||
|
|
||||||
if create_rq.status_code != 201:
|
if create_rq.status_code != 201:
|
||||||
return resp
|
return render_template("index_authorised.html", message={
|
||||||
|
'type': 'error',
|
||||||
|
'text': f"unexpected error when creating playlist {playlist_name}"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
playlist_id = resp.get('id')
|
playlist_id = resp.get('id')
|
||||||
db.user_add_playlist(user_id, playlist_id, count, counttype)
|
db.user_add_playlist(user_id, playlist_id, count, counttype)
|
||||||
|
|
||||||
@ -135,13 +139,10 @@ def cb():
|
|||||||
|
|
||||||
token_rq = rq.post(f"{SPOTIFY_TOKEN_ENDPOINT}", data = data, headers = headers)
|
token_rq = rq.post(f"{SPOTIFY_TOKEN_ENDPOINT}", data = data, headers = headers)
|
||||||
if token_rq.status_code != rq.codes.ok:
|
if token_rq.status_code != rq.codes.ok:
|
||||||
resp = make_response(json.dumps({
|
return render_template("index_authorised.html", message={
|
||||||
'status_code': token_rq.status_code,
|
'type': 'error',
|
||||||
'resp:': token_rq.json(),
|
'text': f"unable to authenticate with spotify. please try again later."
|
||||||
'data': data
|
})
|
||||||
}))
|
|
||||||
resp.headers.set('Content-Type', 'application/json')
|
|
||||||
return resp
|
|
||||||
|
|
||||||
resp = token_rq.json()
|
resp = token_rq.json()
|
||||||
spotify_token = resp['access_token']
|
spotify_token = resp['access_token']
|
||||||
@ -149,9 +150,12 @@ def cb():
|
|||||||
refresh_token = resp['refresh_token']
|
refresh_token = resp['refresh_token']
|
||||||
|
|
||||||
me_rq = rq.get(f"{SPOTIFY_API_ENDPOINT}/me", headers = { 'Authorization': f"Bearer {spotify_token}" })
|
me_rq = rq.get(f"{SPOTIFY_API_ENDPOINT}/me", headers = { 'Authorization': f"Bearer {spotify_token}" })
|
||||||
resp = me_rq.json()
|
|
||||||
if me_rq.status_code != 200:
|
if me_rq.status_code != 200:
|
||||||
return resp
|
return render_template("index_authorised.html", message={
|
||||||
|
'type': 'error',
|
||||||
|
'text': f"unable to authenticate with spotify. please try again later."
|
||||||
|
})
|
||||||
|
resp = me_rq.json()
|
||||||
spotify_id = resp['id']
|
spotify_id = resp['id']
|
||||||
|
|
||||||
db.add_user(user_secret, spotify_token, spotify_id, token_expires, refresh_token, client_secret_expires=USER_SECRET_EXPIRATION)
|
db.add_user(user_secret, spotify_token, spotify_id, token_expires, refresh_token, client_secret_expires=USER_SECRET_EXPIRATION)
|
||||||
|
Loading…
Reference in New Issue
Block a user