如何使用节点处理Admin SDK initializeApp中的错误? [英] How to handle errors in Admin SDK initializeApp with node?

查看:36
本文介绍了如何使用节点处理Admin SDK initializeApp中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Admin SDK中使用以下代码

If I use the following code with the Admin SDK

admin.initializeApp({
  credential: admin.credential.cert({
    projectId: '<PROJECT_ID>',
    clientEmail: 'foo@<PROJECT_ID>.iam.gserviceaccount.com',
    privateKey: '-----BEGIN PRIVATE KEY-----\n<KEY>\n-----END PRIVATE KEY-----\n'
  }),
  databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});

我如何知道它是否失败?出于某种原因,我发现很奇怪的文档中没有提及处理成功/错误的信息.

How am I going to know if it failed? For some reason there's no mention about handling success/error in the docs which I find very strange.

推荐答案

您会知道它失败了,因为它会崩溃,并在程序输出中显示有意义的错误消息.初始化失败的唯一方法是,如果您没有正确配置admin SDK.初始化实际上并不会尝试访问数据库或执行任何其他可能失败的操作.其他失败将被您做出的其他API调用拒绝.

You'll know it failed because it will crash with a meaningful error message in the output of your program. The only way init can fail is if you haven't configured the admin SDK properly. Initialization doesn't actually try to reach the database or do anything else that could fail. Other failures will be seen be rejected promises from other API calls you make.

这篇关于如何使用节点处理Admin SDK initializeApp中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆