我已按照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
这个系统是否仍在运行,或者是否有一个工作连接器示例我可以查看是否有我缺少的东西?
答案 0 :(得分:0)
查看我们的一些开源社区连接器,例如npm Downloads Connector和Stack Overflow Questions Connector,以查看错误处理示例。除非不显示错误消息,否则请确保isAdminUser()
函数正在为测试人员返回true
。错误处理主要面向getData()
。目前,它可能无法满足其他所需功能的需要。