node.js - Firebase https 函数在调用时返回“内部错误”
问题描述
我正在尝试从我的代码中调用 https firebase 函数。问题是,当调用我的函数时返回带有代码internal
的错误,错误消息也是 internal
. 我试图在网上搜索这个问题,我在描述这个错误代码的 firebase 文档上发现的一件事是有问题。所以我很困惑。这就是函数的调用方式:
export const getPlanDetails = (plan: string) => async (dispatch: Dispatch) => {
try {
dispatch({
type: ERROR,
payload: null,
});
dispatch({
type: IS_FETCHING,
payload: true,
});
const request = functions.httpsCallable("getPlanDetails");
const response = await request({ plan: plan });
dispatch({
type: GET_PLAN_DETAIL,
payload: {
currency: response.data["currency"],
name: response.data["name"],
interval: response.data["interval"],
amount: response.data["amount"],
},
});
} catch (error) {
console.log(error);
dispatch({
type: ERROR,
payload: "An error occured getting the plan details",
});
} finally {
dispatch({
type: IS_FETCHING,
payload: false,
});
}
};
我可以确认问题不是来自我的函数,因为当我在另一个项目上调用它时它工作得很好。因此,我还检查了该函数是否可以从我的 firebase 控制台上传到谷歌。它也不能是我的功能失败,因为我在它发生时设置了自定义错误消息。
这是功能代码:
exports.getPlanDetails = functions.https.onCall(async (data, context) => {
try {
const plan = await stripe.plans.retrieve(data.plan);
return {
currency: plan["currency"],
name: plan["nickname"],
interval: plan["interval"],
amount: plan["amount"],
};
} catch (error) {
console.log(error);
await reportError(error, { user: context.auth.uid });
throw new functions.https.HttpsError("something went wrong ...", error);
}
});
这就是我初始化functions
var 的方式:
import * as firebase from "firebase";
import { store } from "../redux";
import { AUTH_STATE_CHANGE } from "../redux/types/auth.type";
const firebaseConfig = {
//secret
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
const auth = firebase.auth();
const firestore = firebase.firestore();
const functions = firebase.functions();
export { auth, firestore, functions };
我认为 firebase 已经很好地初始化了,因为 auth 或 firestore 等其他服务运行良好
谢谢您的帮助
解决方案
推荐阅读
- python - BeautifulSoup 为我知道存在的标签返回 None
- python - 需要帮助从按下的按钮收集数据。[Python]
- docker - 为什么在运行`docker build`时我的maven依赖项获取失败并重置连接?
- java - 如何在 replaceAll 中的符号后替换字母/数字
- css - 如何将 CSS 与 Webpack 捆绑
- openlayers - 多字符串功能未显示在 openlayers 地图上?
- sql - 将组合约束添加到数据库表中
- testing - How to get contents of a NSTextFieldCell in a cell-based outline when the user quits while editing
- sublimetext3 - index.sublime-project and index.sublime-workspace files
- git - Gitbook force changing uppercase directories to lowercase in GitHub