Reputation: 19843
I have a function like below
export const detectClient = functions.https.onRequest(async (request, response) => {
try
{
const data = await foo();
return response.status(200).send(data);
}
catch(err) {
throw new functions.https.HttpsError('internal', 'error', err);
}
}
The issue is when error happens firebase function doesn't terminate
If I use
return response.status(500).end('error');
it will terminate correctly.
So I am not sure what is the correct way and if I need to use response.status(500)
what is the usage of throw new functions.https.HttpsError
Upvotes: 0
Views: 468
Reputation: 317467
You are confusing error handling for callable functions with error handling for HTTP functions. The function you're showing is an HTTP type function (because it's declared with functions.https.onRequest
), which doesn't use the error handling conventions as callable functions. For HTTP type functions, you should explicitly send the response as you've shown in your question.
Upvotes: 3