in packages/web-api-send-notification-runner/src/sender/notification-sender.ts [64:119]
private async sendNotificationWithRetry(
notificationSenderConfigData: NotificationSenderMetadata,
): Promise<Partial<OnDemandPageScanResult>> {
let runFailed = false;
let numberOfRetries = 1;
let notificationState: NotificationState = 'sendFailed';
let error: NotificationError = null;
let statusCode: number;
const scanConfig = await this.getScanConfig();
while (numberOfRetries <= scanConfig.maxSendNotificationRetryCount) {
this.logger.logInfo(`Sending scan result notification. Retry count ${numberOfRetries}.`);
let response;
try {
response = await this.notificationSenderWebAPIClient.sendNotification(notificationSenderConfigData);
statusCode = response.statusCode;
if (this.responseParser.isSuccessStatusCode(response)) {
this.logger.logInfo(`Scan result notification request succeeded. Retry count ${numberOfRetries}.`);
notificationState = 'sent';
error = null;
break;
} else {
this.logger.logInfo(
`Scan result notification request failed. Retry count ${numberOfRetries}, statusCode: ${response.statusCode}, body: ${response.body}`,
);
error = { errorType: 'HttpErrorCode', message: `${response.body}` };
}
runFailed = false; // reset run state if retry succeeded
} catch (e) {
runFailed = true;
this.logger.logError(`Scan result notification request failed. Error: ${(e as Error).message}`);
error = { errorType: 'InternalError', message: (e as Error).message };
}
numberOfRetries = numberOfRetries + 1;
if (numberOfRetries <= scanConfig.maxSendNotificationRetryCount) {
await this.system.wait(5000);
}
}
if (runFailed) {
this.logger.trackEvent('SendNotificationTaskFailed', undefined, { failedScanNotificationTasks: 1 });
}
if (notificationState !== 'sent') {
this.logger.trackEvent('ScanRequestNotificationFailed', undefined, { scanRequestNotificationsFailed: 1 });
}
return {
id: notificationSenderConfigData.scanId,
notification: this.generateNotification(notificationSenderConfigData.scanNotifyUrl, notificationState, error, statusCode),
};
}