Search code examples
looker-studio

Throwing errors to users from Community Connector


I've followed the guide at https://developers.google.com/datastudio/connector/error-handling#non-admin-messages for handing back an error to the users from the getData method. However, even when using the provided example method to throw an error to the user, I still get the generic error on all my reports:

Logging Method:

/**
   * Throws an error that complies with the community connector spec.
   * @param {string} message The error message.
   * @param {boolean} userSafe Determines whether this message is safe to show
   *     to non-admin users of the connector. true to show the message, false
   *     otherwise. false by default.
   */
  function throwConnectorError(message, userSafe) {
    userSafe = (typeof userSafe !== 'undefined' &&
                typeof userSafe === 'boolean') ?  userSafe : false;
    if (userSafe) {
      message = 'DS_USER:' + message;
    }

    throw new Error(message);
  }

Calling Code:

try{
    //SOME CODE HERE THAT THROWS ERROR
}catch (ex){
    logConnectorError("getData: Unexpected Error:", ex);
    if (ex.message !== null){    
      throwConnectorError("Unable to fetch data due to server error: " + ex.message, true);
    }
    else{
      throwConnectorError("Unexpected error: " + ex, true);
    }
  }

Error when running:

Error Details
The server encountered an internal error and was unable to complete your request.
Error ID: 0e1e80fb

Is this system still working or is there an example working connector I can view to see if there's something I'm missing?


Solution

  • Have a look at some of our Open Source Community Connectors like the npm Downloads Connector and the Stack Overflow Questions Connector to see examples of error handling. Make sure that your isAdminUser() function is returning true for the tester unless the error messages won't be shown. The error handling is mostly geared towards getData(). For now, it might not work as desired for other required functions.