'Google Cloud Function request node module 404

When i checking my "img" entry on firebase with google cloud function and the request module i get an error but only when i deployed it on local emulator it works.

Error i get on my cloud logs:

removeExpiredDocuments
Exception from a finished function: TypeError: Cannot read properties of undefined (reading 'statusCode')

enter image description hereExample URL for 404:
https://ch.cat-ret.assets.lidl/catalog5media/ch/article/5104560/third/lg/5104560_01.jpg

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const requesth = require('request');
admin.initializeApp();

exports.removeExpiredDocuments = functions.region('europe-west1').runWith({ memory: "256MB" }).pubsub.schedule("every 1 hours").onRun(async (context) => {
    const db = admin.firestore();

    const snaps = await db.collection("products").get();
    let promises = [];
    snaps.forEach((snap) => {
        requesth(snap.data().img, function (error, response) {
            functions.logger.info('[img] error: ' + error, { structuredData: true });
            if ((response) && (response.statusCode) == 404) {
                promises.push(snap.ref.delete());
                functions.logger.info('[img] not found ' + snap.data().name, { structuredData: true });
            }
        });
    });

    return Promise.all(promises);
});

I wanna use google cloud function for checking if the "img" entry is statusCode 404 and if its statusCode 404 delete the document.

#edit new random error without changed anything #2 Image of random change errors



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source