Cannot handle errors using formidable in node.js

I’m using node.js formidable to upload files to my express server.

I want to be able to handle some of the errors, like the a file wasn’t chosen, the file size outside of the limit, file type check etc. and the be able to return a specific error based to the client based on the result.

But I just can’t seem to find the righta good way to do this?

I’m trying to do this in form.parse() but I’m have issues here because it stops processing the file if it exceeds the file limits? this means I can’t do any kind of check as there is no data in file.uploaded?

This is my code:

app.post('/putdata', async (req, res, error) => {

    let fileUploaded = '';
    var form = new formidable.IncomingForm({

        //* Set up incoming data requirments
        maxFileSize: 1 * 1024 * 1024,
        minFileSize: 1,

    });

    console.log('Max file size allowed : ' + form.options.minFileSize);
    console.log('Min file size allowed : ' + form.options.maxFileSize);

    const uploaded = await new Promise((resolve,reject) => {

    form.parse(req, function (err, fields, files) {

    
        //* Handle no file uploaded
        if(!files.uploaded) {
            console.log('file not selected.')
            res.status(400).send('No file recieved for upload');
            return;
        } 

        if (err) {
            console.log('error : ' + err)
            return;
        }

        fileUploaded = 'complete';
        resolve(true);
    });

    });
    console.log(fileUploaded);

});

What I am I doing wrong here?

Thanks for any helpsuggestions.