Fix XML parsing with invalid LTI response

An invalid XML response may be returned if the LTI provider is unavailable and cannot handle our request. We decided against logging in Sentry as this affects a third party functionality we cannot fix ourselves.
Fixes CODEOCEAN-G2
This commit is contained in:
Sebastian Serth
2022-12-07 23:00:21 +01:00
parent 6bfda8e552
commit bec235c8d6

View File

@ -170,8 +170,14 @@ module Lti
# Reduce score by 100%
normalized_lit_score *= 0.0
end
response = provider.post_replace_result!(normalized_lit_score)
{code: response.response_code, message: response.post_response.body, status: response.code_major, score_sent: normalized_lit_score}
begin
response = provider.post_replace_result!(normalized_lit_score)
{code: response.response_code, message: response.post_response.body, status: response.code_major, score_sent: normalized_lit_score}
rescue IMS::LTI::XMLParseError
# A parsing error might happen if the LTI provider is down and doesn't return a valid XML response
{status: 'error'}
end
else
{status: 'unsupported'}
end