首页 文章

从社区连接器向用户投掷错误

提问于
浏览
1

我已按照https://developers.google.com/datastudio/connector/error-handling#non-admin-messages的指南,将错误从getData方法传回给用户 . 但是,即使使用提供的示例方法向用户抛出错误,我仍然会在所有报告中收到一般错误:

记录方法:

/**
   * 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);
  }

电话代码:

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 Details
The server encountered an internal error and was unable to complete your request.
Error ID: 0e1e80fb

这个系统是否仍在工作或是否有一个工作连接器示例我可以查看是否有我遗漏的东西?

1 回答

  • 0

    查看一些我们的开源社区连接器,如npm Downloads ConnectorStack Overflow Questions Connector,以查看错误处理示例 . 除非不显示错误消息,否则请确保isAdminUser()函数正在为测试仪返回 true . 错误处理主要面向 getData() . 目前,它可能无法满足其他所需功能的需要 .

相关问题