Skip to content

Commit

Permalink
Safe check json for checking is_wharton
Browse files Browse the repository at this point in the history
  • Loading branch information
judtinzhang committed Sep 10, 2023
1 parent 7291d8e commit e5a0341
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/gsr_booking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ def check_wharton(self):
try:
response = requests.get(
url, headers={"Authorization": f"Token {settings.WHARTON_TOKEN}"}
).json()
if "type" in response:
)

if response.status_code != 200:
return None

res_json = response.json()
if "type" in res_json:
# check if user is wharton
return response["type"] == "whartonMBA" or response["type"] == "whartonUGR"
return res_json["type"] == "whartonMBA" or res_json["type"] == "whartonUGR"
else:
# accomodate for inconsistent responses
return False
Expand Down

0 comments on commit e5a0341

Please sign in to comment.