我写了一个小的联系表单,该表单调用Firebase Cloud函数将请求存储到Cloud Firestore。一切正常,除了在60秒后网站引发以下错误:
Error: deadline-exceeded
这是我的云功能:
exports.newRequest = functions.https.onCall((data, context) => {
return admin
.firestore()
.collection("requests")
.add(data)
.then(ref => {
console.log(`New request written. ${ref}`)
return ref.id
})
.catch(err => {
throw new functions.https.HttpsError("unknown", error.message, error)
})
})
这是函数调用:
const functions = firebase.functions()
const addMessage = functions.httpsCallable(`newRequest`)
addMessage({
name: name,
contact: contact,
message: message,
timestamp: new Date(Date.now()).toLocaleString(),
})
.then(result => {
console.log(`Cloud function called successfully. Ref: ${result.data}`)
})
.catch(error => {
// Getting the Error details.
var code = error.code
var message = error.message
var details = error.details
console.log(code, message, details)
})
有人知道如何解决此问题吗?
编辑:
这是云功能日志:
7:19:33.751 PM newRequest Function execution started
7:19:33.751 PM newRequest Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:19:33.755 PM newRequest Function execution took 5 ms, finished with status code: 204
7:19:33.896 PM newRequest Function execution started
7:19:33.896 PM newRequest Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:19:34.744 PM newRequest New request written. [object Object]
7:19:34.746 PM newRequest Function execution took 851 ms, finished with status code: 200
我的详细设置:
import * as firebase from "firebase/app"
const firebaseConfig = {}
useEffect(() => {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig)
} else {
console.log(firebase.apps)
}
})
import * as firebase from "firebase/app"
import "firebase/functions"
const handleSubmit = evt => {
evt.preventDefault()
const addMessage = firebase.functions().httpsCallable(`newRequest`)
addMessage({
name: name,
contact: contact,
message: message,
timestamp: new Date(Date.now()).toLocaleString(),
})
.then(result => {
console.log(`Cloud function called successfully. Ref: ${result.data}`)
})
.catch(error => {
// Getting the Error details.
var code = error.code
var message = error.message
var details = error.details
console.log(code, message, details)
})
resetName()
resetContact()
resetMessage()
}
这是chrome开发工具所说的:
Exception: Error: deadline-exceeded at new HttpsErrorImpl (http://localhost:8000/commons.js:4409:28) at http://localhost:8000/commons.js:4715:20
code: "deadline-exceeded"
details: undefined
message: "deadline-exceeded"
stack: "Error: deadline-exceeded↵ at new HttpsErrorImpl (http://localhost:8000/commons.js:4409:28)↵ at http://localhost:8000/commons.js:4715:20"
__proto__: Error
这是承诺创建者:
/**
* Returns a Promise that will be rejected after the given duration.
* The error will be of type HttpsErrorImpl.
*
* @param millis Number of milliseconds to wait before rejecting.
*/
function failAfter(millis) {
return new Promise(function (_, reject) {
setTimeout(function () {
reject(new HttpsErrorImpl('deadline-exceeded', 'deadline-exceeded'));
}, millis);
});
}
自几天以来,我一直在遇到此问题,我不知道它从哪里来(:>
答案 0 :(得分:0)
是React Hooks的“ useEffect”吗?
如果是,则您的Firebase初始化(在useEffect中)在每次渲染时完成。
如果您希望useEffect仅应用一次(例如componentDidMount),则应在第二个参数中传递一个空数组。
uint32_t