Firebase cloud function finishes with status code 304Get unhandled promise error but when I add catch I get type boolean is not assignableFirebase cloud functions is very slowCloud functions for firebase finished with status: 'timeout'What's the difference between Cloud Firestore and the Firebase Realtime Database?How to import CSV or JSON to firebase cloud firestoreFirebase Cloud Functions https.onCall finished with status code: 204Firebase Cloud Function Finished with status ''error''Code snippet executes after function is finished in Firebase Cloud FunctionsFirebase Cloud Functions: Promise not resolvingFirebase cloud function returns 304 error and then restarts

What would prevent chimeras from reproducing with each other?

Is it possible to fly backward if you have really strong headwind?

Getting UPS Power from One Room to Another

Live action TV show where High school Kids go into the virtual world and have to clear levels

Does the Nuka-Cola bottler actually generate nuka cola?

What aircraft was used as Air Force One for the flight between Southampton and Shannon?

Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?

Can a human be transformed into a Mind Flayer?

Increase speed altering column on large table to NON NULL

Analogy between an unknown in an argument, and a contradiction in the principle of explosion

Why is long-term living in Almost-Earth causing severe health problems?

tabular: caption and align problem

What are the implications when matrix's lowest eigenvalue is equal to 0?

Section numbering in binary

What should I discuss with my DM prior to my first game?

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

Was planting UN flag on Moon ever discussed?

Why does this query, missing a FROM clause, not error out?

How to write a convincing religious myth?

How do i export activities related to an account with a specific recordtype?

Is the use of umgeben in the passive unusual?

Arduino wrap or Subclass print() to work with multiple Serial

Are polynomials with the same roots identical?

Confused with atmospheric pressure equals plastic balloon’s inner pressure



Firebase cloud function finishes with status code 304


Get unhandled promise error but when I add catch I get type boolean is not assignableFirebase cloud functions is very slowCloud functions for firebase finished with status: 'timeout'What's the difference between Cloud Firestore and the Firebase Realtime Database?How to import CSV or JSON to firebase cloud firestoreFirebase Cloud Functions https.onCall finished with status code: 204Firebase Cloud Function Finished with status ''error''Code snippet executes after function is finished in Firebase Cloud FunctionsFirebase Cloud Functions: Promise not resolvingFirebase cloud function returns 304 error and then restarts






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm having trouble finding out why the following function finished with a status code of 304 rather then sending the 200 response. The documents update as required, but I want to get the correct status code.



const firestoreInstance = admin.firestore();

export async function onTwitchGiveawayPostback(req, res)
const reward = 1;

const userName = await utils.getParameterByName('name', req.originalUrl);

if (!userName) throw new Error('User Display Name is not set on REQLoot :(');

const displayNameDocPath = firestoreInstance.collection('displayNames').doc(userName);

return displayNameDocPath.get().then(snapshot => snapshot.data()).then(displayNameDocDetails =>
if (!displayNameDocDetails)
res.status(200).send('User Display Name: ' + userName + ' is not set on REQLoot :(');
return Promise.resolve('Ok');
else
const uid = displayNameDocDetails.uid;

const staminaEntryDoc = firestoreInstance.collection(utils.API_URLS.userStaminaBalanceSheet + '/' + uid + '/entries').doc();
const userDocPath = firestoreInstance.collection('users').doc(uid);

const promises = [];
promises.push(
userDocPath.get(),
);

return Promise.all(promises).then((snapshots) =>
return Promise.all(snapshots.map((doc) =>
return doc.data();
)).then(data =>
const userDocDetails = data[0];

const serverTimestamp = admin.firestore.Timestamp.now();

const batch = firestoreInstance.batch();

const staminaBalanceSheetDescription = 'winner';
const staminaPrev = userDocDetails.stamina;
const staminaNew = staminaPrev + reward;

batch.update(userDocPath,
stamina: staminaNew,
updatedAt: serverTimestamp,
);

// Update the User's stamina balance sheet
batch.set(staminaEntryDoc,
description: staminaBalanceSheetDescription,
stamina:
previous: staminaPrev,
new: staminaNew,
,
staminaAmount: reward,
updatedAt: serverTimestamp,
);

return batch.commit();
)
.then(() =>
res.status(200).send(userName + ' won some stamina!');
)
.catch((err) =>
console.error(err)
return err;
);
)

)
.catch(err => console.log(err))



Other posts have mentioned that the function always needs to return a Promise, but I think I've added them where necessary. What am I missing that is preventing a normal 200 response?










share|improve this question




























    1















    I'm having trouble finding out why the following function finished with a status code of 304 rather then sending the 200 response. The documents update as required, but I want to get the correct status code.



    const firestoreInstance = admin.firestore();

    export async function onTwitchGiveawayPostback(req, res)
    const reward = 1;

    const userName = await utils.getParameterByName('name', req.originalUrl);

    if (!userName) throw new Error('User Display Name is not set on REQLoot :(');

    const displayNameDocPath = firestoreInstance.collection('displayNames').doc(userName);

    return displayNameDocPath.get().then(snapshot => snapshot.data()).then(displayNameDocDetails =>
    if (!displayNameDocDetails)
    res.status(200).send('User Display Name: ' + userName + ' is not set on REQLoot :(');
    return Promise.resolve('Ok');
    else
    const uid = displayNameDocDetails.uid;

    const staminaEntryDoc = firestoreInstance.collection(utils.API_URLS.userStaminaBalanceSheet + '/' + uid + '/entries').doc();
    const userDocPath = firestoreInstance.collection('users').doc(uid);

    const promises = [];
    promises.push(
    userDocPath.get(),
    );

    return Promise.all(promises).then((snapshots) =>
    return Promise.all(snapshots.map((doc) =>
    return doc.data();
    )).then(data =>
    const userDocDetails = data[0];

    const serverTimestamp = admin.firestore.Timestamp.now();

    const batch = firestoreInstance.batch();

    const staminaBalanceSheetDescription = 'winner';
    const staminaPrev = userDocDetails.stamina;
    const staminaNew = staminaPrev + reward;

    batch.update(userDocPath,
    stamina: staminaNew,
    updatedAt: serverTimestamp,
    );

    // Update the User's stamina balance sheet
    batch.set(staminaEntryDoc,
    description: staminaBalanceSheetDescription,
    stamina:
    previous: staminaPrev,
    new: staminaNew,
    ,
    staminaAmount: reward,
    updatedAt: serverTimestamp,
    );

    return batch.commit();
    )
    .then(() =>
    res.status(200).send(userName + ' won some stamina!');
    )
    .catch((err) =>
    console.error(err)
    return err;
    );
    )

    )
    .catch(err => console.log(err))



    Other posts have mentioned that the function always needs to return a Promise, but I think I've added them where necessary. What am I missing that is preventing a normal 200 response?










    share|improve this question
























      1












      1








      1


      1






      I'm having trouble finding out why the following function finished with a status code of 304 rather then sending the 200 response. The documents update as required, but I want to get the correct status code.



      const firestoreInstance = admin.firestore();

      export async function onTwitchGiveawayPostback(req, res)
      const reward = 1;

      const userName = await utils.getParameterByName('name', req.originalUrl);

      if (!userName) throw new Error('User Display Name is not set on REQLoot :(');

      const displayNameDocPath = firestoreInstance.collection('displayNames').doc(userName);

      return displayNameDocPath.get().then(snapshot => snapshot.data()).then(displayNameDocDetails =>
      if (!displayNameDocDetails)
      res.status(200).send('User Display Name: ' + userName + ' is not set on REQLoot :(');
      return Promise.resolve('Ok');
      else
      const uid = displayNameDocDetails.uid;

      const staminaEntryDoc = firestoreInstance.collection(utils.API_URLS.userStaminaBalanceSheet + '/' + uid + '/entries').doc();
      const userDocPath = firestoreInstance.collection('users').doc(uid);

      const promises = [];
      promises.push(
      userDocPath.get(),
      );

      return Promise.all(promises).then((snapshots) =>
      return Promise.all(snapshots.map((doc) =>
      return doc.data();
      )).then(data =>
      const userDocDetails = data[0];

      const serverTimestamp = admin.firestore.Timestamp.now();

      const batch = firestoreInstance.batch();

      const staminaBalanceSheetDescription = 'winner';
      const staminaPrev = userDocDetails.stamina;
      const staminaNew = staminaPrev + reward;

      batch.update(userDocPath,
      stamina: staminaNew,
      updatedAt: serverTimestamp,
      );

      // Update the User's stamina balance sheet
      batch.set(staminaEntryDoc,
      description: staminaBalanceSheetDescription,
      stamina:
      previous: staminaPrev,
      new: staminaNew,
      ,
      staminaAmount: reward,
      updatedAt: serverTimestamp,
      );

      return batch.commit();
      )
      .then(() =>
      res.status(200).send(userName + ' won some stamina!');
      )
      .catch((err) =>
      console.error(err)
      return err;
      );
      )

      )
      .catch(err => console.log(err))



      Other posts have mentioned that the function always needs to return a Promise, but I think I've added them where necessary. What am I missing that is preventing a normal 200 response?










      share|improve this question














      I'm having trouble finding out why the following function finished with a status code of 304 rather then sending the 200 response. The documents update as required, but I want to get the correct status code.



      const firestoreInstance = admin.firestore();

      export async function onTwitchGiveawayPostback(req, res)
      const reward = 1;

      const userName = await utils.getParameterByName('name', req.originalUrl);

      if (!userName) throw new Error('User Display Name is not set on REQLoot :(');

      const displayNameDocPath = firestoreInstance.collection('displayNames').doc(userName);

      return displayNameDocPath.get().then(snapshot => snapshot.data()).then(displayNameDocDetails =>
      if (!displayNameDocDetails)
      res.status(200).send('User Display Name: ' + userName + ' is not set on REQLoot :(');
      return Promise.resolve('Ok');
      else
      const uid = displayNameDocDetails.uid;

      const staminaEntryDoc = firestoreInstance.collection(utils.API_URLS.userStaminaBalanceSheet + '/' + uid + '/entries').doc();
      const userDocPath = firestoreInstance.collection('users').doc(uid);

      const promises = [];
      promises.push(
      userDocPath.get(),
      );

      return Promise.all(promises).then((snapshots) =>
      return Promise.all(snapshots.map((doc) =>
      return doc.data();
      )).then(data =>
      const userDocDetails = data[0];

      const serverTimestamp = admin.firestore.Timestamp.now();

      const batch = firestoreInstance.batch();

      const staminaBalanceSheetDescription = 'winner';
      const staminaPrev = userDocDetails.stamina;
      const staminaNew = staminaPrev + reward;

      batch.update(userDocPath,
      stamina: staminaNew,
      updatedAt: serverTimestamp,
      );

      // Update the User's stamina balance sheet
      batch.set(staminaEntryDoc,
      description: staminaBalanceSheetDescription,
      stamina:
      previous: staminaPrev,
      new: staminaNew,
      ,
      staminaAmount: reward,
      updatedAt: serverTimestamp,
      );

      return batch.commit();
      )
      .then(() =>
      res.status(200).send(userName + ' won some stamina!');
      )
      .catch((err) =>
      console.error(err)
      return err;
      );
      )

      )
      .catch(err => console.log(err))



      Other posts have mentioned that the function always needs to return a Promise, but I think I've added them where necessary. What am I missing that is preventing a normal 200 response?







      angular firebase promise google-cloud-firestore






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 20:50









      FlignatsFlignats

      364410




      364410






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The issue was CORS.



          The function was executing and updating firestore, but returning a 304 status code and not sending the string payload. Updating the function with the following line:



          res.set('Access-Control-Allow-Origin', '*');



          Allowed for a 200 status code and proper string being sent on completion.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328443%2ffirebase-cloud-function-finishes-with-status-code-304%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The issue was CORS.



            The function was executing and updating firestore, but returning a 304 status code and not sending the string payload. Updating the function with the following line:



            res.set('Access-Control-Allow-Origin', '*');



            Allowed for a 200 status code and proper string being sent on completion.






            share|improve this answer



























              0














              The issue was CORS.



              The function was executing and updating firestore, but returning a 304 status code and not sending the string payload. Updating the function with the following line:



              res.set('Access-Control-Allow-Origin', '*');



              Allowed for a 200 status code and proper string being sent on completion.






              share|improve this answer

























                0












                0








                0







                The issue was CORS.



                The function was executing and updating firestore, but returning a 304 status code and not sending the string payload. Updating the function with the following line:



                res.set('Access-Control-Allow-Origin', '*');



                Allowed for a 200 status code and proper string being sent on completion.






                share|improve this answer













                The issue was CORS.



                The function was executing and updating firestore, but returning a 304 status code and not sending the string payload. Updating the function with the following line:



                res.set('Access-Control-Allow-Origin', '*');



                Allowed for a 200 status code and proper string being sent on completion.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 16:48









                FlignatsFlignats

                364410




                364410





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328443%2ffirebase-cloud-function-finishes-with-status-code-304%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript