Skip to content

Commit

Permalink
Wd 11854 fix authentication issues for credentials (canonical#13944)
Browse files Browse the repository at this point in the history
* Add error handling to scheduling API

* check if your exams gets a 401 and then ask user to relogin
  • Loading branch information
abhigyanghosh30 authored Jun 12, 2024
1 parent 6756eba commit 69b8bc0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
7 changes: 5 additions & 2 deletions webapp/shop/api/ua_contracts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def post_assessment_reservation(
"startsAt": starts_at,
"countryCode": country_code,
},
error_rules=["default"],
error_rules=[],
).json()
return req

Expand Down Expand Up @@ -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):
Expand Down
47 changes: 34 additions & 13 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 69b8bc0

Please sign in to comment.