Skip to main content
added 2 characters in body
Source Link
Doug Stevenson
  • 320.5k
  • 37
  • 458
  • 474

I use TypeScript in my callable Cloud functions. Their structure looks something like this:

exports.sayHello = functions.https.onCall(async (data, context) => {  try {   const email: string = data.email;   const isStudent: boolean = data.isStudent   if (isStudent) {   const mathGrade: string = data.mathgrade;   try {   // Access Firestore   } catch (error) {   // Throw Https error   }   } else {   const mainSubject: string = data.mainsubject;   try {   // Access Firestore   } catch (error) {   // Throw Https error   }   }  } catch (error) {   // Handle type error (the typecasting failed because of the json data)  } }); 

});

My question now is if the Https errors I throw would be caught by the outer try catch block, because what I want is send them to client

I use TypeScript in my callable Cloud functions. Their structure looks something like this:

exports.sayHello = functions.https.onCall(async (data, context) => { try { const email: string = data.email; const isStudent: boolean = data.isStudent if (isStudent) { const mathGrade: string = data.mathgrade; try { // Access Firestore } catch (error) { // Throw Https error } } else { const mainSubject: string = data.mainsubject; try { // Access Firestore } catch (error) { // Throw Https error } } } catch (error) { // Handle type error (the typecasting failed because of the json data) } 

});

My question now is if the Https errors I throw would be caught by the outer try catch block, because what I want is send them to client

I use TypeScript in my callable Cloud functions. Their structure looks something like this:

exports.sayHello = functions.https.onCall(async (data, context) => {  try {   const email: string = data.email;   const isStudent: boolean = data.isStudent   if (isStudent) {   const mathGrade: string = data.mathgrade;   try {   // Access Firestore   } catch (error) {   // Throw Https error   }   } else {   const mainSubject: string = data.mainsubject;   try {   // Access Firestore   } catch (error) {   // Throw Https error   }   }  } catch (error) {   // Handle type error (the typecasting failed because of the json data)  } }); 

My question now is if the Https errors I throw would be caught by the outer try catch block, because what I want is send them to client

Source Link
Patrick
  • 622
  • 8
  • 22

Firebase Cloud Functions: Throw Https error inside try catch block

I use TypeScript in my callable Cloud functions. Their structure looks something like this:

exports.sayHello = functions.https.onCall(async (data, context) => { try { const email: string = data.email; const isStudent: boolean = data.isStudent if (isStudent) { const mathGrade: string = data.mathgrade; try { // Access Firestore } catch (error) { // Throw Https error } } else { const mainSubject: string = data.mainsubject; try { // Access Firestore } catch (error) { // Throw Https error } } } catch (error) { // Handle type error (the typecasting failed because of the json data) } 

});

My question now is if the Https errors I throw would be caught by the outer try catch block, because what I want is send them to client