简体   繁体   中英

How can I send a custom response from a firebase cloud function?

I've written a firebase cloud function and everything works as expected, however when trying to read the response from the client side, the data I've returned from the cloud function isn't included in the response.

Here's my cloud function:

exports.employeeExists = functions.https.onRequest((request, response) => {
  return response.status(500).json({
    data: {
      type: constants.REQUEST_ERROR,
      error: 'ERROR MESSAGE'
    }
  });
});

Here's my client-side request:


fetch('cloud function url', options)
      .then((response) => {
        console.log(JSON.stringify(response));
});

The output I get on the client-side log is the response with the correct status code that I've set (500), however the data that I send with the response isn't present.

Is there something I'm missing?

After some struggling I decided to use Axios instead of the built in fetch() function and now I am able to retrieve the response data I'm expecting just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM