我已经实现了一个 HTTPs (onCall) 函数,它会向客户端抛出一些错误,或者在工作成功完成时返回true 。问题是我不明白为什么要返回 true (因为当我抛出错误时我不返回false)。
HTTP协议需要返回一个response给客户端来完成一个请求,我应该给客户端返回什么?我正在考虑删除我抛出的错误并返回一个经典的 HTTP 响应(状态代码、正文……)。
有任何想法吗?这是我在做什么:
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 };
*/
}
宝慕林4294392
噜噜哒
随时随地看视频慕课网APP
相关分类