Debugging cui.js

Once you have a cui.js object and begin making API calls, it is often helpful see debug-level info from cui.js.

A browser-specified setting toggles cui.js debugging on or off, without any underlying code changes or redeployments. In that way, your App users will not normally see cui.js messages in their browser console. However, during troubleshooting scenarios, the log can be enabled/disabled.

Always check cui.js version

Before an exhaustive troubleshooting scenario, it is recommended that you confirm which version of cui.js is loaded in your App. You would be surprised how many issues can be resolved by correctly loading the desired version of cui.js into your App, or by updating to the latest version.

  • From browser:
    • Start your App.
    • Open browser console and enter MyCuiJs.version()
    • The version will print in the console.
  • From project directory:
    • Open the node_modules/@covisint/cui.js/dist directory.
    • Open cui.min.js file.
    • The version is visible near the top of the file.

AngularJS AngularJS Debug Tip

If you store a reference to the cui.js object in $rootScope,
you can access that reference from the browser console, as follows…

> angular.element(‘body’).scope().YourRootScopeVariable.version()

Turn on cui.js debug info

There are two ways to turn on cui.js debug info. When troubleshooting an App that is running in someone else’s browser, use the temporary method. When developing, choose either of the permanent methods.

  • Temporarily:
    • Open browser console and enter cui.enableLog()
  • Permanently:
    • Add cui.enableLog() in your App code and (re)start the App.
    • …or…
    • Open your browser’s Local Storage settings
      • add cui.log = true
      • refresh the browser

Use cui.log() instead of console.log()

If you use console.log() statements in your App, they must be stripped out of the code before building a dist version, or all of your debug messages will pollute the browser console, and potentially slow down your App as well.

On the other hand, if you replace console.log() with cui.log(), then your console messages will now behave like internal cui.js log messages. The concept described above for temporarily enabling the messages will apply for your App messages. You can toggle the messages on and off as needed, and no additional effort is required to remove the messages when building a dist version.

Because cui.log() is simply a conditionally-activated binding on top of console.log(), it accepts the exact same parameter(s) as console.log(). It is also shorter to type.

Error handling in the App

Do not reinvent the wheel. Call parseError(). It knows how to unpack error messages that are deep inside the error objects returned by the Covisint APIs.

In the event that the error object is not output via a Covisint API, parseError() will examine other common error structures to extract a meaningful underlying message.

 myCuiJs.countOrganizations().then(function(response) {
    var count = response;
 }).fail(function(err) {
    // ...Use cui.js to extract message from error object.
    var errStr = myCuiJs.parseError(err);