From 9804c8b8e051ae98c5ab7d3e9517ecbe1cbfd424 Mon Sep 17 00:00:00 2001 From: moloko Date: Fri, 16 Oct 2020 13:03:12 +0100 Subject: [PATCH] add the error code into the errors for getValue, setValue and commit switch to 'Property value shorthand' where possible setValue - only get error code if the set command returns false change info > errorInfo and code > errorCode for clarity improve wording/formatting of error messages --- example.json | 26 +++++++++++++------------- js/scorm/error.js | 24 ++++++++++++------------ js/scorm/wrapper.js | 23 +++++++++++------------ 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/example.json b/example.json index 591cb2e5..371f25f4 100644 --- a/example.json +++ b/example.json @@ -29,19 +29,19 @@ } } - // to be added to course/en/course.json + // to be added to course/en/course.json (note: you only need to add the ones you want to change/translate) "_spoor": { "_messages": { - "title": "An error has occurred", - "pressOk": "Press 'OK' to view detailed debug information to send to technical support.", - "CLIENT_COULD_NOT_CONNECT": "Course could not connect to the LMS", - "SERVER_STATUS_UNSUPPORTED": "ScormWrapper::getStatus: invalid lesson status '{{status}}' received from LMS", - "CLIENT_STATUS_UNSUPPORTED": "ScormWrapper::setStatus: the status '{{status}}' is not supported.", - "CLIENT_COULD_NOT_COMMIT": "Course could not commit data to the LMS\nError {{code}}: {{info}}\nLMS Error Info: {{diagnosticInfo}}", - "CLIENT_NOT_CONNECTED": "Course is not connected to the LMS", - "CLIENT_COULD_NOT_FINISH": "Course could not finish", - "CLIENT_COULD_NOT_GET_PROPERTY": "Course could not get {{property}}\nError Info: {{info}}\nLMS Error Info: {{diagnosticInfo}}", - "CLIENT_COULD_NOT_SET_PROPERTY": "Course could not set {{property}} to {{value}}\nError Info: {{info}}\nLMS Error Info: {{diagnosticInfo}}", - "CLIENT_INVALID_CHOICE_VALUE": "Numeric choice/matching response elements must use a value from 0 to 35 in SCORM 1.2" + "title": "An error has occurred", + "pressOk": "Press 'OK' to view detailed debug information to send to technical support.", + "CLIENT_COULD_NOT_CONNECT": "The course could not connect to the LMS", + "SERVER_STATUS_UNSUPPORTED": "An invalid lesson status of '{{{status}}}' was received from LMS", + "CLIENT_STATUS_UNSUPPORTED": "The status '{{{status}}}' is not supported.", + "CLIENT_COULD_NOT_COMMIT": "There was a problem saving data to the LMS\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}", + "CLIENT_NOT_CONNECTED": "The course is not connected to the LMS", + "CLIENT_COULD_NOT_FINISH": "The course was unable to finish the LMS session", + "CLIENT_COULD_NOT_GET_PROPERTY": "Unable to get the value of {{property}} from the LMS\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}", + "CLIENT_COULD_NOT_SET_PROPERTY": "Unable to set {{property}} to: {{{value}}}\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}", + "CLIENT_INVALID_CHOICE_VALUE": "Numeric choice/matching response elements must use a value from 0 to 35 in SCORM 1.2" } - } + } diff --git a/js/scorm/error.js b/js/scorm/error.js index 1446ceed..3bc903a3 100644 --- a/js/scorm/error.js +++ b/js/scorm/error.js @@ -12,24 +12,24 @@ define(function() { ScormError.CLIENT_COULD_NOT_CONNECT = 'CLIENT_COULD_NOT_CONNECT'; ScormError.SERVER_STATUS_UNSUPPORTED = 'SERVER_STATUS_UNSUPPORTED'; // status ScormError.CLIENT_STATUS_UNSUPPORTED = 'CLIENT_STATUS_UNSUPPORTED'; // status - ScormError.CLIENT_COULD_NOT_COMMIT = 'CLIENT_COULD_NOT_COMMIT'; // code, info, diagnosticInfo + ScormError.CLIENT_COULD_NOT_COMMIT = 'CLIENT_COULD_NOT_COMMIT'; // errorCode, errorInfo, diagnosticInfo ScormError.CLIENT_NOT_CONNECTED = 'CLIENT_NOT_CONNECTED'; ScormError.CLIENT_COULD_NOT_FINISH = 'CLIENT_COULD_NOT_FINISH'; - ScormError.CLIENT_COULD_NOT_GET_PROPERTY = 'CLIENT_COULD_NOT_GET_PROPERTY'; // property, info, diagnosticInfo - ScormError.CLIENT_COULD_NOT_SET_PROPERTY = 'CLIENT_COULD_NOT_SET_PROPERTY'; // property, value, info, diagnosticInfo - ScormError.CLIENT_INVALID_CHOICE_VALUE = 'CLIENT_INVALID_CHOICE_VALUE'; // value + ScormError.CLIENT_COULD_NOT_GET_PROPERTY = 'CLIENT_COULD_NOT_GET_PROPERTY'; // property, errorCode, errorInfo, diagnosticInfo + ScormError.CLIENT_COULD_NOT_SET_PROPERTY = 'CLIENT_COULD_NOT_SET_PROPERTY'; // property, value, errorCode, errorInfo, diagnosticInfo + ScormError.CLIENT_INVALID_CHOICE_VALUE = 'CLIENT_INVALID_CHOICE_VALUE'; ScormError.defaultMessages = { title: 'An error has occurred', pressOk: `Press 'OK' to view detailed debug information to send to technical support.`, - CLIENT_COULD_NOT_CONNECT: 'Course could not connect to the LMS', - SERVER_STATUS_UNSUPPORTED: `ScormWrapper::getStatus: invalid lesson status '{{status}}' received from LMS`, - CLIENT_STATUS_UNSUPPORTED: `ScormWrapper::setStatus: the status '{{status}}' is not supported.`, - CLIENT_COULD_NOT_COMMIT: 'Course could not commit data to the LMS\nError {{code}}: {{info}}\nLMS Error Info: {{diagnosticInfo}}', - CLIENT_NOT_CONNECTED: 'Course is not connected to the LMS', - CLIENT_COULD_NOT_FINISH: 'Course could not finish', - CLIENT_COULD_NOT_GET_PROPERTY: 'Course could not get {{property}}\nError Info: {{info}}\nLMS Error Info: {{diagnosticInfo}}', - CLIENT_COULD_NOT_SET_PROPERTY: 'Course could not set {{property}} to {{value}}\nError Info: {{info}}\nLMS Error Info: {{diagnosticInfo}}', + CLIENT_COULD_NOT_CONNECT: 'The course could not connect to the LMS', + SERVER_STATUS_UNSUPPORTED: `An invalid lesson status of '{{{status}}}' was received from LMS`, + CLIENT_STATUS_UNSUPPORTED: `The status '{{{status}}}' is not supported.`, + CLIENT_COULD_NOT_COMMIT: 'There was a problem saving data to the LMS\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}', + CLIENT_NOT_CONNECTED: 'The course is not connected to the LMS', + CLIENT_COULD_NOT_FINISH: 'The course was unable to finish the LMS session', + CLIENT_COULD_NOT_GET_PROPERTY: 'Unable to get the value of {{property}} from the LMS\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}', + CLIENT_COULD_NOT_SET_PROPERTY: `Unable to set {{property}} to: '{{{value}}}'\n\nError: {{errorCode}} - {{{errorInfo}}}\nLMS Error Info: {{{diagnosticInfo}}}`, CLIENT_INVALID_CHOICE_VALUE: 'Numeric choice/matching response elements must use a value from 0 to 35 in SCORM 1.2' }; diff --git a/js/scorm/wrapper.js b/js/scorm/wrapper.js index 7952f57d..92b4aac7 100644 --- a/js/scorm/wrapper.js +++ b/js/scorm/wrapper.js @@ -292,8 +292,8 @@ define([ const errorCode = this.scorm.debug.getCode(); this.handleError(new ScormError(CLIENT_COULD_NOT_COMMIT, { - code: errorCode, - info: this.scorm.debug.getInfo(errorCode), + errorCode, + errorInfo: this.scorm.debug.getInfo(errorCode), diagnosticInfo: this.scorm.debug.getDiagnosticInfo(errorCode) })); } @@ -391,7 +391,8 @@ define([ } else { this.handleError(new ScormError(CLIENT_COULD_NOT_GET_PROPERTY, { property: property, - info: this.scorm.debug.getInfo(errorCode), + code: errorCode, + errorInfo: this.scorm.debug.getInfo(errorCode), diagnosticInfo: this.scorm.debug.getDiagnosticInfo(errorCode) })); } @@ -414,18 +415,16 @@ define([ } const success = this.scorm.set(property, value); - const errorCode = this.scorm.debug.getCode(); - if (!success) { - /** - * Some LMSes have an annoying tendency to return false from a set call even when it actually worked fine. - * So, we should throw an error _only_ if there was a valid error code... - */ + // Some LMSes have an annoying tendency to return false from a set call even when it actually worked fine. + // So we should only throw an error if there was a valid error code... + const errorCode = this.scorm.debug.getCode(); if (errorCode !== 0) { this.handleError(new ScormError(CLIENT_COULD_NOT_SET_PROPERTY, { - property: property, - value: value, - info: this.scorm.debug.getInfo(errorCode), + property, + value, + errorCode, + errorInfo: this.scorm.debug.getInfo(errorCode), diagnosticInfo: this.scorm.debug.getDiagnosticInfo(errorCode) })); } else {