diff --git a/common/db.py b/common/db.py index e9dc7dd..9ffce83 100644 --- a/common/db.py +++ b/common/db.py @@ -96,6 +96,9 @@ class Db: 'grant_type': 'refresh_token', 'refresh_token': refresh_token, }) + if res.status_code != 200: + return None + print(res.status_code) print(res.content) res = res.json() diff --git a/web/src/app.py b/web/src/app.py index dcb5079..db7e698 100644 --- a/web/src/app.py +++ b/web/src/app.py @@ -93,11 +93,15 @@ def index(): 'description': f"{count}{counttype}" }) - resp = create_rq.json() 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') 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) if token_rq.status_code != rq.codes.ok: - resp = make_response(json.dumps({ - 'status_code': token_rq.status_code, - 'resp:': token_rq.json(), - 'data': data - })) - resp.headers.set('Content-Type', 'application/json') - return resp + return render_template("index_authorised.html", message={ + 'type': 'error', + 'text': f"unable to authenticate with spotify. please try again later." + }) resp = token_rq.json() spotify_token = resp['access_token'] @@ -149,9 +150,12 @@ def cb(): refresh_token = resp['refresh_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: - 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'] db.add_user(user_secret, spotify_token, spotify_id, token_expires, refresh_token, client_secret_expires=USER_SECRET_EXPIRATION)