I have created a canaries to test my api. I want to get the result based on the response status "ok". Is that possible to edit the response from canary script.
const apiCanaryBlueprint = async function () {
// Handle validation for positive scenario
const validateSuccessfull = async function(res) {
return new Promise((resolve, reject) => {
if (res.statusCode < 200 || res.statusCode > 299) {
throw res.statusCode + ' ' + res.statusMessage;
}
let responseBody = '';
let response = '';
res.on('data', (d) => {
responseBody = "Success";
response=+d;
});
res.on('end', () => {
// Add validation on 'responseBody' here if required.
// var JSONObject = JSON.parse(response);
if(response['floodLocationEligibility']=='Yes')
{
responseBody="Eligible"
}
resolve();
});
});
};
Output Response Body:
{"requestAddress":"330 Elizabeth Rd, San Antonio, TX 78209, USA","location":{"lat":29.4725011,"lon":-98.4534393},"floodLocationEligibility":"Yes","status":"OK"}
Im getting 200 response with above reponse body. I need ony status having "OK". Can anyone suggest me how can i get it. Is that possible to change the script. I attaached the script and response.
question from:
https://stackoverflow.com/questions/65917989/aws-synthetics-canary-script-based-on-the-response-body 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…