<p>I am trying to write a cron job which takes an excel file from SFTP server and upload the data on mongo DB.</p>
<p>Now, suppose there are errors in cronjob like sftp connection failure due to some credentials issue or path from where the file needs to be picked up from is not present, then the control is going inside catch in the below code snippet but instead of marking the cron as Error, it is showing as completed on kubernetes.</p>
<p>I have attached a basic sample code below of the cron job to get an idea about what I am trying to say.</p>
<pre><code>exports.fsmOverallPerformanceData = async (req, res) =&gt; {
    let sftp = new Client;
    const fileName = &quot;FSM_Performance_Data.xlsx&quot;
    const remote = &quot;/home/SI_MARCOM_TOPS/SI_JHDSFTP/SND/&quot;
    const remotePath = remote + fileName
    const localePath = &quot;./fsmperformance.csv&quot;;
    sftp.connect(config.sftpSetting, 'once').then(() =&gt; {
        sftp.fastGet(remotePath, localePath, {}).then(() =&gt; {

        }).catch((err) =&gt; {
            console.log(err, 'FSM Performance fastGet method error'); // this is getting printed
        })
    }).catch((err) =&gt; {
        console.log(err, 'SFTP Connect method error'); // this is getting printed
    });
    setTimeout(() =&gt; {
        process.exit();
    }, 300000);
}
</code></pre>
<p>Thanks in advance for any suggestions or help.</p>

<p>You must ensure that the process exits with a non-zero exit code. Your <code>catch</code> blocks could use a <code>process.exit(1)</code> and <code>throw Error</code>.</p>
