marcdacz / compare-pdf

Standalone node module that compares pdfs
MIT License
62 stars 21 forks source link

No try catch block to catch any await promise rejections in comparePdfByImage #24

Closed humphreyn closed 2 years ago

humphreyn commented 2 years ago

The function comparePdfByImage in ./functions/compareImage.js has no try catch block so any promise rejections by await calls to imageEngine.* are not caught

I would add a try catch block inside the ..new Promise and either reject the error or resolve it with a failed status

const comparePdfByImage = async (compareDetails) => {
    return new Promise(async (resolve, reject) => {
        try {
                ..... // original code block
                .....
                .....
                .....

        } catch (error) {
                        // reject or resolve it with failed status
            reject(error);  
            resolve({ status: 'failed',  error: error });
        }
    });
marcdacz commented 2 years ago

Thanks for raising this. Fixed it in this commit and will be released in the next one.