diff --git a/app/controllers/lti_api_controller.rb b/app/controllers/lti_api_controller.rb index 0e4180f9e2b..56adea785af 100644 --- a/app/controllers/lti_api_controller.rb +++ b/app/controllers/lti_api_controller.rb @@ -35,7 +35,7 @@ class LtiApiController < ApplicationController xml = Nokogiri::XML.parse(request.body) - lti_response = BasicLTI::BasicOutcomes.process_request(@tool, xml) + lti_response = check_outcome BasicLTI::BasicOutcomes.process_request(@tool, xml) render :text => lti_response.to_xml, :content_type => 'application/xml' end @@ -45,7 +45,7 @@ class LtiApiController < ApplicationController def legacy_grade_passback verify_oauth - lti_response = BasicLTI::BasicOutcomes.process_legacy_request(@tool, params) + lti_response = check_outcome BasicLTI::BasicOutcomes.process_legacy_request(@tool, params) render :text => lti_response.to_xml, :content_type => 'application/xml' end @@ -176,4 +176,15 @@ class LtiApiController < ApplicationController generated_signature: @signature.signature } end + + def check_outcome(outcome) + if ['unsupported', 'failure'].include? outcome.code_major + opts = {type: :grade_passback} + error_info = Canvas::Errors::Info.new(request, @domain_root_account, @current_user, opts).to_h + capture_outputs = Canvas::Errors.capture("Grade pass back #{outcome.code_major}", error_info) + outcome.description += "\n[EID_#{capture_outputs[:error_report]}]" + end + + outcome + end end diff --git a/lib/basic_lti/basic_outcomes.rb b/lib/basic_lti/basic_outcomes.rb index 2e1d452e24b..b707182e9d6 100644 --- a/lib/basic_lti/basic_outcomes.rb +++ b/lib/basic_lti/basic_outcomes.rb @@ -66,6 +66,7 @@ module BasicLTI unless res.handle_request(tool) res.code_major = 'unsupported' + res.description = 'Request could not be handled. ¯\_(ツ)_/¯' end return res end @@ -75,6 +76,7 @@ module BasicLTI unless res.handle_request(tool) res.code_major = 'unsupported' + res.description = 'Legacy request could not be handled. ¯\_(ツ)_/¯' end return res end diff --git a/spec/apis/lti/grade_passback_spec.rb b/spec/apis/lti/grade_passback_spec.rb index 2e3c3a1fcdb..1974db33b0b 100644 --- a/spec/apis/lti/grade_passback_spec.rb +++ b/spec/apis/lti/grade_passback_spec.rb @@ -259,8 +259,12 @@ XML expect(response.content_type).to eq 'application/xml' xml = Nokogiri::XML.parse(response.body) expect(xml.at_css('imsx_POXEnvelopeResponse > imsx_POXHeader > imsx_POXResponseHeaderInfo > imsx_statusInfo > imsx_codeMajor').content).to eq failure_type - expect(xml.at_css('imsx_description').content).to eq error_message if error_message expect(@assignment.submissions.where(user_id: @student)).not_to be_exists + desc = xml.at_css('imsx_description').content.match(/(?.+)\n\[EID_(?[^\]]+)\]/) + expect(desc[:description]).to eq error_message if error_message + expect(desc[:error_report]).to_not be_empty + + end def check_success @@ -341,7 +345,7 @@ XML expect(response).to be_success xml = Nokogiri::XML.parse(response.body) expect(xml.at_css('imsx_codeMajor').content).to eq 'failure' - expect(xml.at_css('imsx_description').content).to eq "No score given" + expect(xml.at_css('imsx_description').content).to match /^No score given/ expect(@assignment.submissions.where(user_id: @student)).not_to be_exists end @@ -351,7 +355,7 @@ XML expect(response).to be_success xml = Nokogiri::XML.parse(response.body) expect(xml.at_css('imsx_codeMajor').content).to eq 'failure' - expect(xml.at_css('imsx_description').content).to eq "Score is not between 0 and 1" + expect(xml.at_css('imsx_description').content).to match /^Score is not between 0 and 1/ expect(@assignment.submissions.where(user_id: @student)).not_to be_exists end @@ -362,7 +366,7 @@ XML expect(response).to be_success xml = Nokogiri::XML.parse(response.body) expect(xml.at_css('imsx_codeMajor').content).to eq 'failure' - expect(xml.at_css('imsx_description').content).to eq "Assignment has no points possible." + expect(xml.at_css('imsx_description').content).to match /^Assignment has no points possible\./ end it "should pass if assignment has 0 points possible" do