How to handle Bad JSON in Firebase Cloud Functions?

Viewed 4853

I'm creating a firebase application which uses firebase-cloud-functions.

index.js

exports.auth = functions.https.onRequest((request, response) => {
  response.status(200).send({
    status : "Some Status"
  });
}

This is very simple functions. I want to make a POST request on the endpoint with some payload. When I tested the API using Firebase Cloud Function Emulator and POSTman with bad json

{
    "phoneNumber: "9632725300"
}

The server just crashed! My question is how to handle the bad request in firebase functions like these.

with this error enter image description here

3 Answers
Related