modules/utils.js
/** 
 *  Process the response from Secplugs scan 
 *  
 **/
Process the response from Secplugs scan
Process the response from Secplugs scan
function processAPIResponse(security_api, api_key, response, scan_progress_callback) {
    if (!response.ok) {
        var err_message = "";
        const status_code = response.status;
        if (status_code === 403 || status_code === 429) {
            err_message = "Ensure key is correct with sufficient credits.";
        }
        else {
            err_message = `The request to the service failed with ${status_code}`;
        }
        if (scan_progress_callback) {
            const scan_status = {
                url: null,
                status: 'failure',
                score: null,
                verdict: null,
                report_id: null,
                err_message: err_message
            };
            scan_progress_callback(scan_status);
        }
        return;
    }
    response.json()
        .then(json_response => {
            var scan_status = map_json_response_2_scan_status(json_response);
            if (scan_progress_callback) {
                scan_progress_callback(scan_status);
            }
            const report_id = json_response['report_id'];
            if (json_response['status'] == 'pending') {
                setTimeout(() => {
                    poll_for_report(
                        report_id,
                        security_api,
                        api_key,
                        scan_progress_callback);
                }, 0  );
            }
        });
}
function processAPIResponse ( security_api , api_key , response , scan_progress_callback ) { if ( ! response . ok ) { var err_message = "" ; const status_code = response . status ; if ( status_code === 403 || status_code === 429 ) { err_message = "Ensure key is correct with sufficient credits." ; } else { err_message = ` ${ status_code } ` ; } if ( scan_progress_callback ) { const scan_status = { url : null , status : 'failure' , score : null , verdict : null , report_id : null , err_message : err_message } ; scan_progress_callback ( scan_status ) ; } return ; } response . json ( ) . then ( json_response => { var scan_status = map_json_response_2_scan_status ( json_response ) ; if ( scan_progress_callback ) { scan_progress_callback ( scan_status ) ; } const report_id = json_response [ 'report_id' ] ; if ( json_response [ 'status' ] == 'pending' ) { setTimeout ( ( ) => { poll_for_report ( report_id , security_api , api_key , scan_progress_callback ) ; } , 0 ) ; } } ) ; }
Process the response from Secplugs scan
Process the response from Secplugs scan
// First handle api failure // Format message // Send failure status if we have a call back // Build status // Update progress  // Done // Load json // Check status and report back // Get report id // Reschedule if still pending // Schedule a poll /* Poll immediately */