Skip to content

Commit

Permalink
MDL-77086 badges: Improve debugging
Browse files Browse the repository at this point in the history
Display more information, like the status error, when the badge can't
be sent to the backpack.
  • Loading branch information
sarjona committed Feb 13, 2023
1 parent 1ea152c commit 597564d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion badges/classes/backpack_api2p1.php
Expand Up @@ -228,8 +228,19 @@ public function put_assertions($hash) {
$msg['status'] = \core\output\notification::NOTIFY_SUCCESS;
$msg['message'] = get_string('addedtobackpack', 'badges');
} else {
$statuserror = $response->status->error;
if (is_array($statuserror)) {
// Although the specification defines that status error is a string, some providers, like Badgr, are wrongly
// returning an array. It has been reported, but adding this extra check doesn't hurt, just in case.
$statuserror = implode($statuserror);
}
$data = [
'badgename' => $data['assertion']['badge']['name'],
'error' => $statuserror,
];

$msg['status'] = \core\output\notification::NOTIFY_ERROR;
$msg['message'] = get_string('backpackexporterror', 'badges', $data['assertion']['badge']['name']);
$msg['message'] = get_string('backpackexporterrorwithinfo', 'badges', $data);
}
return $msg;
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/badges.php
Expand Up @@ -129,6 +129,7 @@
$string['backpackemailverifysuccess'] = 'Thanks for verifying your email address. You are now connected to your backpack.';
$string['backpackemailverifytokenmismatch'] = 'The token in the link you clicked does not match the stored token. Make sure you clicked the link in most recent email you received.';
$string['backpackexporterror'] = 'Can\'t export the badge to backpack';
$string['backpackexporterrorwithinfo'] = 'Can\'t export the badge "{$a->badgename}" to backpack. Error: {$a->error}';
$string['backpackimport'] = 'Badge import settings';
$string['backpackimport_help'] = 'After the backpack connection is successfully established, badges from your backpack can be displayed on your badges page and your profile page.
Expand Down

0 comments on commit 597564d

Please sign in to comment.