代码之家  ›  专栏  ›  技术社区  ›  molc

从社区连接器向用户抛出错误

  •  1
  • molc  · 技术社区  · 8 年前

    我跟随导游在 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 回复  |  直到 8 年前
        1
  •  0
  •   Minhaz Kazi    8 年前

    看看我们的一些开源社区连接器,比如 npm Downloads Connector Stack Overflow Questions Connector 查看错误处理示例。确保您的 isAdminUser() 函数正在返回 true 对于测试仪,除非不会显示错误消息。错误处理主要针对 getData() . 目前,它可能无法像其他所需功能那样工作。