Catching getValue errors, same as setValue

This commit is contained in:
Jonathan Putney
2021-05-27 08:57:37 -04:00
parent 1a5d8d3241
commit 758ac91000
2 changed files with 17 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "scorm-again",
"version": "1.5.3",
"version": "1.6.0",
"description": "A modern SCORM JavaScript run-time library for AICC, SCORM 1.2, and SCORM 2004",
"main": "dist/scorm-again.min.js",
"directories": {

View File

@@ -28,6 +28,7 @@ export default class BaseAPI {
logLevel: global_constants.LOG_LEVEL_ERROR,
selfReportSessionTime: false,
alwaysSendTotalTime: false,
strict_errors: true,
responseHandler: function(xhr) {
let result;
if (typeof xhr !== 'undefined') {
@@ -185,7 +186,21 @@ export default class BaseAPI {
this.#error_codes.RETRIEVE_BEFORE_INIT,
this.#error_codes.RETRIEVE_AFTER_TERM)) {
if (checkTerminated) this.lastErrorCode = 0;
returnValue = this.getCMIValue(CMIElement);
try {
returnValue = this.getCMIValue(CMIElement);
} catch (e) {
if (e instanceof ValidationError) {
this.lastErrorCode = e.errorCode;
returnValue = global_constants.SCORM_FALSE;
} else {
if (e.message) {
console.error(e.message);
} else {
console.error(e);
}
this.throwSCORMError(this.#error_codes.GENERAL);
}
}
this.processListeners(callbackName, CMIElement);
}