Skip to content

Commit 8ca12b5

Browse files
committed
feat: store error representation in qt-variable
1 parent 146e39d commit 8ca12b5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

classes/constants.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class constants {
3636
public const QT_VAR_SCORING_STATE = '_scoringstate';
3737
/** @var string */
3838
public const QT_VAR_RESPONSE = 'qpy_response';
39+
/** @var string */
40+
public const QT_VAR_ERROR = '_qpy_error';
3941

4042
/** @var string This isn't needed after the action has been processed, so it's not a qt var. */
4143
public const FORM_DRAFT_AREAS = 'qpy_draft_areas';

question.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
use qtype_questionpy\constants;
26+
use qtype_questionpy\exception\request_error;
2627
use qtype_questionpy\local\api\api;
2728
use qtype_questionpy\local\api\attempt;
2829
use qtype_questionpy\local\api\attempt_ui;
@@ -372,7 +373,7 @@ public function summarise_response(array $response) {
372373
}
373374
}
374375

375-
return $summary ?: '-';
376+
return $summary;
376377
}
377378

378379
/**
@@ -427,6 +428,10 @@ public function grade_response(array $response): array {
427428
$event->trigger();
428429
debugging($event->get_description(), backtrace: $t->getTrace());
429430

431+
// Our question behaviour constructs an error message containing this error representation.
432+
$error = $t instanceof request_error ? $t->requesterrorcode->value : $t::class . "({$t->getCode()}";
433+
$this->get_behaviour()->get_pending_step()->set_qt_var(constants::QT_VAR_ERROR, $error);
434+
430435
// As the server was not able to score the response, we mark this question with manual scoring.
431436
return [0, question_state::$needsgrading];
432437
}

0 commit comments

Comments
 (0)