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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?