我想在nodejs应用程序中添加一个错误报告,该应用程序将向GCP上的stackdriver API报告错误。我已经遵循了报告错误所需的所有步骤,但当我报告错误时,我得到了错误
ERROR:@google-cloud/error-reporting: Encountered an error while attempting to transmit an error to the Stackdriver Error Reporting API. ApiError: User not authorized.
整个错误堆栈是
ERROR:@google-cloud/error-reporting: Encountered an error while attempting to transmit an error to the Stackdriver Error Reporting API. ApiError: User not authorized.
at new ApiError (/Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/@google-cloud/common/build/src/util.js:59:15)
at Util.parseHttpRespBody (/Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/@google-cloud/common/build/src/util.js:194:38)
at Util.handleResp (/Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/@google-cloud/common/build/src/util.js:135:117)
at /Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/@google-cloud/common/build/src/util.js:434:22
at onResponse (/Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/retry-request/index.js:214:7)
at /Applications/XAMPP/xamppfiles/htdocs/web-dev/kiddopia.com/node_modules/teeny-request/build/src/index.js:219:13
at processTicksAndRejections (node:internal/process/task_queues:94:5)
我的错误报告助手是
const { ErrorReporting } = require('@google-cloud/error-reporting');
module.exports = class ErrorReportHelper {
constructor() {
this.errorReporter = new ErrorReporting({
projectId: 'project-id',
reportMode: 'always',
keyFilename: 'service.json'
});
}
report(message) {
this.errorReporter.report(message);
}
express() {
return this.errorReporter.express();
}
}
任何帮助感激不尽。谢谢
1条答案
按热度按时间nbewdwxp1#
您需要通过Google控制台将“错误报告编写器”权限添加到您的服务帐户/应用程序:
1.转到Google控制台https://console.cloud.google.com/iam-admin/iam
1.选择您的项目
1.找到应用程序的主服务帐户
1.单击服务帐户旁边的“编辑”
1.向下滚动并点击“添加另一个角色”
1.找到“错误报告编写器”并将其添加
确保它被保存,你应该是好的。