diff --git a/webapp/shop/api/ua_contracts/api.py b/webapp/shop/api/ua_contracts/api.py index aa9c6ae715b..5955e2fb228 100644 --- a/webapp/shop/api/ua_contracts/api.py +++ b/webapp/shop/api/ua_contracts/api.py @@ -382,7 +382,7 @@ def post_assessment_reservation( "startsAt": starts_at, "countryCode": country_code, }, - error_rules=["default"], + error_rules=[], ).json() return req @@ -450,12 +450,15 @@ def get_annotated_contract_items( if product_tags: params["productTags"] = product_tags + error_rules = [] + if "cue" not in product_tags: + error_rules = ["default"] return self._request( method="get", path="/web/annotated-contract-items", params=params, - error_rules=["default"], + error_rules=error_rules, ).json() def handle_error(self, error, error_rules=None): diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index e7abe777d56..a3696d1e0c8 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -336,14 +336,32 @@ def cred_schedule(ua_contracts_api, trueability_api, **_): contract_long_id=contract_long_id, ) else: - response = ua_contracts_api.post_assessment_reservation( - contract_item_id, - first_name, - last_name, - timezone, - starts_at.isoformat(), - country_code, - ) + try: + response = ua_contracts_api.post_assessment_reservation( + contract_item_id, + first_name, + last_name, + timezone, + starts_at.isoformat(), + country_code, + ) + except Exception as error: + flask.current_app.extensions["sentry"].captureException( + extra={ + "user_info": user_info(flask.session), + "request_url": error.request.url, + "request_headers": error.request.headers, + "response_headers": error.response.headers, + "response_body": error.response.json(), + } + ) + error = error.response.json()["message"] + return flask.render_template( + "/credentials/schedule.html", + error=error, + time_delay=time_delay, + ) + if response and "reservation" not in response: error = response["message"] return flask.render_template( @@ -420,19 +438,22 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs): try: exam_contracts = ua_contracts_api.get_annotated_contract_items( - product_tags=["cue"], email=email + email=email, product_tags=["cue"] ) - except UAContractsAPIErrorView as error: + except Exception as 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("/logout?return_to=/credentials/your-exams") + else: + exam_contracts = [] exams_in_progress = [] exams_scheduled = []