- You want to manually report a custom error to StackDriver Error Reporting.
- You don't want to stop the script.
If my understanding is correct, how about this workaround? In this workaround, it uses the method of projects.events.report
in Stackdriver Error Reporting API.
Before you use this sample script, please do the following operations.
- Add
https://www.googleapis.com/auth/cloud-platform
to the scopes using Manifests and others.
- Enable Stackdriver Error Reporting API at API console.
Sample script:
try {
thisMayThrowAnError();
} catch(err) {
var projectId = "project-id-#####"; // Please set the project ID of project including your script.
var payload = { // Please modify this for your situation.
message: "Something Failed",
serviceContext: {service: "sample"},
context: {reportLocation: {functionName: "sampleFunctionName"}},
};
var url = "https://clouderrorreporting.googleapis.com/v1beta1/projects/" + projectId + "/events:report";
var params = {
method: "post",
payload: JSON.stringify(payload),
contentType: "application/json",
headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()},
}
UrlFetchApp.fetch(url, params);
}
Note:
- This is a simple sample script. So please modify to your situation.
- In this script, each value of
payload
is sample values. So please modify to your situation.
- When I called this API, there was the case that the reflection of result is late. So if the result is not reflected to StackDriver Error Reporting after you called the API, please wait a moment.
References:
From your question, I understood that you are using Google Apps Script. If you are using other language, please tell me. If this workaround was not the result you want, I apologize.