From da4b7e01d47c4a6f0966e237e1663d9835914eb0 Mon Sep 17 00:00:00 2001 From: abhigyanghosh30 Date: Thu, 6 Jun 2024 21:29:51 +0530 Subject: [PATCH] check if your exams gets a 401 and then ask user to relogin --- webapp/shop/api/ua_contracts/api.py | 13 +++++++++++++ webapp/shop/cred/views.py | 17 +++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/webapp/shop/api/ua_contracts/api.py b/webapp/shop/api/ua_contracts/api.py index 3b7a9abae8e..e1a91c8d081 100644 --- a/webapp/shop/api/ua_contracts/api.py +++ b/webapp/shop/api/ua_contracts/api.py @@ -458,6 +458,19 @@ def get_annotated_contract_items( error_rules=["default"], ).json() + def get_cue_annotated_contract_items( + self, email: str = "", product_tags: List[str] = [] + ) -> List[dict]: + params = {"email": email} + params["productTags"] = ["cue"] + + return self._request( + method="get", + path="/web/annotated-contract-items", + params=params, + error_rules=[], + ).json() + def handle_error(self, error, error_rules=None): if not error_rules: return diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index 9e6375f4bbb..a34fc998ca1 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -399,20 +399,25 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): agreement_notification = True try: - exam_contracts = ua_contracts_api.get_annotated_contract_items( - product_tags=["cue"], email=email + exam_contracts = ua_contracts_api.get_cue_annotated_contract_items( + email=email ) - except UAContractsAPIErrorView as error: + except Exception as error: + print(error) flask.current_app.extensions["sentry"].captureException( extra={ "user_info": user_info(flask.session), - "request_url": error.request.url, - "request_headers": error.request.headers, + "request_url": flask.request.url, + "request_headers": flask.request.headers, "response_headers": error.response.headers, "response_body": error.response.json(), } ) - exam_contracts = [] + if error.response.status_code == 401: + return flask.redirect("/login?next=/credentials/your-exams") + else: + exam_contracts = [] + exams_in_progress = [] exams_scheduled = []