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.

Be Sociable, Share!
This entry was posted in Run Time Environment. Bookmark the permalink.

One Response to Step 58 – Setting and Storing the Error Code

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>