从社区连接器向用户抛出错误
Throwing errors to users from Community Connector
我已按照 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
这个系统是否仍在工作,或者是否有一个工作连接器示例我可以查看以查看是否缺少某些东西?
看看我们的一些开源社区连接器,例如 npm Downloads Connector and the Stack Overflow Questions Connector to see examples of error handling. Make sure that your isAdminUser()
函数正在为测试人员返回 true
,除非不显示错误消息。错误处理主要针对 getData()
。目前,对于其他所需功能,它可能无法正常工作。
我已按照 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
这个系统是否仍在工作,或者是否有一个工作连接器示例我可以查看以查看是否缺少某些东西?
看看我们的一些开源社区连接器,例如 npm Downloads Connector and the Stack Overflow Questions Connector to see examples of error handling. Make sure that your isAdminUser()
函数正在为测试人员返回 true
,除非不显示错误消息。错误处理主要针对 getData()
。目前,对于其他所需功能,它可能无法正常工作。