MicroStrategy ONE

Creating custom error messages

When you create a custom data connector using the Data Connector SDK, the fetchTable function runs in a NodeJS process. When an error occurs during the running of this process, which defines how to fetch and format the data, only a general error message like "Node JS command may exit unexpectedly" is provided. This makes it difficult to figure out what really happened.

To address this problem, you can create custom errors and error messages. The Data Connector SDK provides APIs for data connectors to pass errors to the IServer at each of the steps in the fetch table phase of the workflow. Each step has a callback function with a parameter that can be used to pass errors and error messages. If no error occurs, you can either pass "void 0" as the value of the parameter or not pass the parameter at all. So, for example, you can pass a specific error for authentication failure and another for an error that occurred when appending data.

If you created a custom data connector with a version of the product prior to 11.0, you must upgrade your MicroStrategy product and replace mstrgdc-1.0.js with mstrgdc-2.0.js to take advantage of the ability to create custom error messages. Simply download mstrgdc_20js.zip, extract the latest version of the mstrgdc-2.0.js Javascript file, and use it to replace the existing Javascript file in your data connector.

Error information can be reported to the IServer at the following points in the workflow:

  • Error occurs in init

    initCallback(error)

  • Error occurs in fetchTable

    doneCallback(table, error)

  • Error occurs in close

    closeCallback(error)

Errors that occur in the fetch data phase generally involve an authentication failure or an error that occurred when appending data.

The error parameter is of String type. It can be plain text or in the following JSON format:

Copy
{
  "errorCode": int,
  "errorMessage": string
}

If you use the JSON format, the IServer will parse it and transform it into an error type inside the IServer. However, you cannot change the key words (“errorCode” and “errorMessage”) and their types (“int” and “string”); if you do, the IServer will assume that it is an error in plain text.

Currently, the only error code that has special meaning is 401, which is translated into “Unauthorized Error”. Other error codes, including errors that are in plain text, are translated into “File Import Error” by default.

Sample JavaScript code to customize the error message for error code 401 is shown below

Copy
myConnector.fetchTable = function(table, params, doneCallback) {
... (other logic)
  // The following is for reporting error when error occur
  var myError={};
  myError.errorCode=401;
  myError.errorMessage="login failed";
  doneCallback(table, JSON.stringify(myError));
}

 

See also