我正在使用 Firebase SDK 函数来获取和发布数据。但是当我从后端收到错误时,我无法捕获它。从后端发送的错误显示在网络中,但我捕获的错误并未捕获从后端发送的详细信息。我该如何解决这个问题?
`
const saveKey = async () => {
const payload = getPayload();
try {
const result = await createKeyFunction({
functionName: 'testName',
payload: payload,
});
} catch (error) {
console.error('error test==>>', error);
}
};`
我发现的错误是:
code: "functions/internal"
customData: undefined
details: undefined
name: "FirebaseError"
message: "internal"
stack: "FirebaseError: internal"
我从后端收到的错误是:
additionalInfo: {error: "AddSecurity is not implemented"}
code: "invalid-argument"
details: {error: "AddSecurity is not implemented"}
message: "AddSecurity is not implemented"
我找到了解决方案。错误需要采用以下格式:
{
error: {
details: {code: "", message: "AddSecurity is not implemented"}
}
}