Step 58 – Setting and Storing the Error Code

OK – an easy step here. I want a place to store the error code, so I introduce a new variable called ‘errorCode’ into api.php.

// ------------------------------------------
//   Status Flags
// ------------------------------------------
var flagFinished = false;
var flagInitialized = false;
var errorCode = '0';

Pretty simple. This variable is accessible to all of the functions that I’ve defined in api.php. So setting an error code is as simple as this (using LMSGetValue as an example):

function LMSGetValue(varname) {

  // not initialized or already finished
  if ((! flagInitialized) || (flagFinished)) { 
    errorCode = '301';
    return '';
  }

  // otherwise, return the requested data
  errorCode = '0';
  return cache[varname];

}

You’ll see that I set ‘301’ if (for some reason) the API hasn’t been initialized, and ‘0’ if the call is successful. Obviously, there are a lot more tests and checks that I need to implement – for example, is the data element readable or not? And is it even supported by the API? I’ll get on to that later.

Next – setting up the API calls to handle the error code.

This entry was posted in Run Time Environment. Bookmark the permalink.

2 Responses to Step 58 – Setting and Storing the Error Code

  1. Pingback: Step 59 – LMSGetLastError, LMSGetErrorString and LMSGetDiagnostic | VSSCORM

  2. Mc Allan says:

    Course index.html file is missing.

Comments are closed.