Hi @shahin24093 ,
you can throw the error in your catch block to make this work.
By having a catch block, you are telling JavaScript “hey, if there is an error thrown in checkIfSpecificerrorid let me (the person who is writing the code) handle it, don’t fail the action”.
By re-throwing the error the action fails when checkIfSpecificerrorid throws. See here:
// optional import of sdk modules
import { execution } from '@dynatrace-sdk/automation-utils';
import { executionsClient } from '@dynatrace-sdk/client-automation';
export default async function ({ execution_id }) {
const ex = await execution(execution_id);
var results: JSON = await executionsClient.getTaskExecutionResult({ executionId: execution_id, id: "execute_dql_query_1" });
var driftResults = results.records;
let errorIdValue = driftResults[0].errorid;
function checkIfSpecificerrorid(value) {
const specificNumber = 6000;
const numericValue = Number(value);
if (numericValue !== specificNumber) {
throw new Error("Value does not match " + specificNumber);
}
console.log("value matches the specific number: " + value);
}
try {
if (errorIdValue !== undefined) {
checkIfSpecificerrorid(errorIdValue);
}
} catch (error) {
console.error(error.message);
throw error
}
}
Note the “throw error” line after the “console.error(error)” line. With this you will get the action to fail. The output will be the following:
