title: Firebase 'Unhandled Rejection' and 'Can't set headers after they are set' JavaScript error
body: <p>Firstly, please note that I am very very new to JS and coding as a general :)</p>
  <p>Desired behaviour:
  I have written the following JS HTTPS Firebase function which, which takes in a query parameter <code>locationId</code>, it performs a GET API call and saves the response back to Firebase. The code correctly saves the data to Firebase as desired. I have come across similar issues but i'm struggling to adapt those solutions to my specific issue below. From what I see, I'm only sending the response once.</p>
  <p>Specific error: The following is the console output</p>
  <blockquote>
  <p>Cannot set headers after they are sent to the client</p>
  <p>Unhandled rejection</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/PLczs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PLczs.png" alt="enter image description here" /></a></p>
  <p>My function:</p>
  <pre><code>exports.doshiiGetMenuForOnboardedVenue = functions.https.onRequest((req, res) =&gt; {
  
    // Forbidding PUT requests.
    if (req.method === 'PUT') {
      return res.status(403).send('Forbidden!');
    }
  
    cors(req, res, () =&gt; {
  
      const locationId = req.query.locationId;
  
      console.log('locationId', locationId);
  
      if (locationId){
  
        console.log('locationId', locationId);
  
        var token = jwttoken();
  
        const options = {
            headers: {
              'content-type': 'application/json',
              'authorization': 'Bearer ' + token}
          };
  
          const uri = 'https://sandbox.doshii.co/partner/v3/locations/' + locationId + '/menu?lastVersion=:lastVersion&amp;filtered=true'
  
          axios.get(uri, options)
            .then(response =&gt; {
  
               return admin.database().ref(`/venue-menus/${locationId}/`).set(response.data)
               .then(response =&gt; {
                 return res.status(200).send(locationId)
               })
               .catch(err =&gt; {
                 return res.status(500).send({error: err})
               })
  
            })
            .then(response =&gt; {
                      return res.status(200).send(locationId)
              })
            .catch(err =&gt; {
              return res.status(500).send({error: err})
            })//end axios
  
      } else {
  
        return res.status(500).send({error: 'locationId missing'})
  
      }//end if-else (!locationId)
  
    })//end cors
  
  });
  </code></pre>