Skip to content

Commit

Permalink
add the error code into the errors for getValue, setValue and commit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
moloko committed Oct 16, 2020
1 parent a549e55 commit 9804c8b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
26 changes: 13 additions & 13 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
24 changes: 12 additions & 12 deletions js/scorm/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

Expand Down
23 changes: 11 additions & 12 deletions js/scorm/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}));
}
Expand Down Expand Up @@ -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)
}));
}
Expand All @@ -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 {
Expand Down

0 comments on commit 9804c8b

Please sign in to comment.