I have implemented a HTTPs (onCall) function that throws some errors to the client or return true if the work is successfully completed. The problem is that I don't see why to return true (because when I throw the errors I don't return false).
As HTTP protocol requires to return a response to the client to finish a request, what should I return to the client? I am thinking to remove the errors I throw and return a classic HTTP reponse (status code, body, ...).
Any ideas? Here is what I am doing:
exports.function = functions
.region("us-central1")
.runWith({ memory: "2GB", timeoutSeconds: 120 })
.https.onCall(async (data, context) => {
// Lazy initialization of the Admin SDK
if (!is_function_initialized) {
// ... stuff
is_uploadImage_initialized = true;
}
// ... asynchronous stuff
// When all promises has been resolved...
// If work completed successfully
return true;
/*
Is it correct instead ???
return {code: "200 OK", date: date, body: message };
*/
// Else, if errors
throw new Error("Please, try again later.");
/*
Is it correct instead ???
return {code: "418 I'm a teapot", date: date, body: message };
*/
}