public async handleRequest()

in packages/web-api/src/controllers/scan-request-controller.ts [46:90]


    public async handleRequest(): Promise<void> {
        await this.init();
        let payload: ScanRunRequest[];
        try {
            payload = this.extractPayload();
        } catch (e) {
            this.context.res = HttpResponse.getErrorResponse(WebApiErrorCodes.malformedRequest);

            return;
        }

        if (payload.length > this.config.maxScanRequestBatchCount) {
            this.context.res = HttpResponse.getErrorResponse(WebApiErrorCodes.requestBodyTooLarge);
            this.logger.logError(`The HTTP request body is too large. The requests count: ${payload.length}.`);

            return;
        }
        const batchId = this.guidGenerator.createGuid();
        this.logger.setCommonProperties({ batchRequestId: batchId });

        const processedData = this.getProcessedRequestData(batchId, payload);
        await this.scanDataProvider.writeScanRunBatchRequest(batchId, processedData.scanRequestsToBeStoredInDb);
        this.context.res = {
            status: 202, // Accepted
            body: this.getResponse(processedData),
        };

        const totalUrls: number = processedData.scanResponses.length;
        const invalidUrls: number = processedData.scanResponses.filter((i) => i.error !== undefined).length;

        this.logger.logInfo('Accepted scan run batch request.', {
            batchId: batchId,
            totalUrls: totalUrls.toString(),
            invalidUrls: invalidUrls.toString(),
            scanRequestResponse: JSON.stringify(processedData.scanResponses),
        });

        const measurements: ScanRequestReceivedMeasurements = {
            totalScanRequests: totalUrls,
            pendingScanRequests: totalUrls - invalidUrls,
            rejectedScanRequests: invalidUrls,
        };

        this.logger.trackEvent('ScanRequestReceived', null, measurements);
    }