首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Google Cloud Functions中未处理的拒绝

Google Cloud Functions中未处理的拒绝
EN

Stack Overflow用户
提问于 2017-12-29 20:57:41
回答 2查看 3.7K关注 0票数 5

我得到了下面的云函数,它工作得很好。它监听实时数据库中的更新,并相应地更新Firestore。

一切都很好,除了当我的用户还不存在我的Firestore数据库时。

这就是我需要处理在Google Cloud Functions日志中看到的Unhandled rejection的地方。

因此,请参阅下面的函数的简化版本,了解我的db.collection("users").where("email", "==", email).get()如何停止函数以向前移动并防止崩溃。

代码语言:javascript
运行
AI代码解释
复制
exports.updateActivities = functions.database.ref("delegates/{userId}/activities").onWrite((event) => {
    //Here I set all the needed variable   
    return rtdb.ref(`delegates/${userId}/email`).once("value", snapshot => {
            //Here I'm fine, email is always present.
        })
        .then(() => {
            db.collection("users").where("email", "==", email).get()

                //This is where I need to handle when there is not matching value, to stop moving forward.

                .then(querySnapshot => {
                    querySnapshot.forEach(val => {
                        console.log("Found match in FireStore " + val.id);
                        firestoreId = val.id;
                    })
                })
                .then(() => {
                    //Here I start my update on Firestore
                });
        })
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-12-29 21:08:39

你应该对你的函数返回的每一个可能被拒绝的承诺使用catch()。这将告诉Cloud Functions您已处理了错误。将解析catch()返回的promise。

通常,您从catch()中记录错误,以便可以在控制台日志中看到它:

代码语言:javascript
运行
AI代码解释
复制
return somePromise
.then(() => { /* do your stuff */ }
.catch(error => { console.error(error) })
票数 5
EN

Stack Overflow用户

发布于 2021-06-20 05:38:47

我在suppressUnhandledRejections中使用了bluebird来解决这个问题:

代码语言:javascript
运行
AI代码解释
复制
import Promise from 'bluebird';

function pool_push(pool, promise)
{
    // In Google Cloud there is a change to crash at `unhandledRejection`.
    // The following trick, basically, tells not to emit
    // `unhandledRejection` since `.catch` will be attached
    // a bit latter.
    const tmp = Promise.resolve(promise);
    tmp.suppressUnhandledRejections();
    pool.items.push(tmp);
}

export default pool_push;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48028366

复制
相关文章
Google 的 Serverless 产品对比:Cloud Run、Cloud Functions、App Engine
Serverless 平台的主要优点是,它们使您可以专注于编写代码,而不必关心管理基础结构,自动扩容或为所用资源支付更多费用。
donghui
2021/02/08
3.6K0
Google 的 Serverless 产品对比:Cloud Run、Cloud Functions、App Engine
分析 Google Cloud Spanner 的架构
在2005、2006年期间,谷歌内部大规模使用了 MySQL 数据库。其中Google Adwords (谷歌广告部门)使用了 90 多个 MySQL Shards(分片)集群方案存储数据,是谷歌内部使用 MySQL 数据库的最大的部门之一。由于系统维护的原因,谷歌广告部门重新规划了 MySQL 集群,整个过程花了 2 年时间。因为谷歌知道它们的数据增长的非常快,再使用 MySQL 这类数据库到未来的某个时刻会非常痛苦。这就是 Spanner 的诞生原因。
哒呵呵
2020/02/19
3.6K0
分析 Google Cloud Spanner 的架构
修复 Google Adsense 漫游器被拒绝的错误
最近登陆 Google Adsense 后台,发现评分卡中收入评分很低,其中抓取工具错误很严重,这个错误的意思是 Google Adsense 的抓取工具无法访问我们网站的网页,因此无法确定其内容并展示相关广告。在这种情况下,Google Adsense 只能展示低收入和低覆盖率的广告,甚至会展示点击率较低的不相关广告。
Denis
2023/04/15
1.1K0
Google Cloud Spanner的实践经验
Cloud Spanner是Google Megastore系统的继承者,Spanner表现出远超前辈的能力。Spanner首次是在Google内部数据中心中出现,而在2017年才对外发布测试版并加入了SQL能力。如今已经在Google云平台上架并拥有大量各个行业的用户。Cloud Spanner数据库是全球范围分布式的关系型/事务数据库,并且Google承诺Cloud Spanner拥有高吞吐量、低延迟和99.999%的高可用性。 接触Cloud Spanner 第一次接触到Google Cloud Sp
ThoughtWorks
2022/08/26
1.5K0
Google Cloud Spanner的实践经验
Google Cloud 宣布支持Go 1.11
The Go Blog Announcing App Engine’s New Go 1.11 Runtime
李海彬
2018/11/08
6240
Deploy TiDB on GCP GKE (Google Cloud)
how to deploy a TiDB cluster on GCP GKE with your laptop (Linux or macOS) for development or testing
杨漆
2021/01/31
8820
Deploy TiDB on GCP GKE (Google Cloud)
Google Cloud 宣布支持Go 1.11
The Go Blog Announcing App Engine’s New Go 1.11 Runtime
李海彬
2018/11/08
6430
SAP HANA中自定义Functions
Hana和其他数据库一样,不但可以定义存储过程,也可以自定义函数。 自定义函数又分为:标量值函数和表值函数两种。
Adil_zhang
2023/05/02
4390
用户代码未处理MetadataException
最近在用EF搭框架的过程中,遇到了很多问题,大部分都是出现在配置文件中,比如说下面这个问题:
全栈程序员站长
2022/08/09
3210
用户代码未处理MetadataException
Top 5 Google Cloud Tools for Application Development
Top Google Cloud tools for web application development. Google gives a wide scope of instruments and administrations for its clients. As one of the top cloud suppliers, Google must stay aware of the aggressive idea of the cloud and discharge administrations to address the issues of its clients. Like AWS and Azure, there is a scope of Google Cloud apparatuses for clients to look over to help facilitate a portion of the pressure that accompanies the open cloud.
用户4822892
2019/10/22
1.2K0
Top 5 Google Cloud Tools for Application Development
切换域名DNS为Google Cloud DNS
前段时间,大约有连续一周,我自己的域名邮箱(腾讯企业邮箱)无法收到邮件,找了各种原因都失败,无论怎么发信都没有,没有拦截,没有进垃圾箱,甚至投诉了下腾讯企业邮箱。
用户1539053
2023/07/24
7600
Flink UDF--Table Functions&Aggregation Functions
   与标量函数相似之处是输入可以0,1,或者多个参数,但是不同之处可以输出任意数目的行数。返回的行也可以包含一个或者多个列。
小勇DW3
2020/01/14
8710
Google停用MapReduce,高调发布Cloud Dataflow
Google已经停用自己研发的,部署在服务器上,用以分析数据的MapReduce,转而支持一个新的超大规模云分析系统Cloud Dataflow。 MapReduce一直是服务器集群上做并行分布式计
大数据文摘
2018/05/21
1.1K0
StormLib Functions
记录一下, 方便查阅 官方链接: The StormLib library//-----------------------------------------------------------------------------  // Functions in StormLib - compatible with Storm.dll  // Typedefs for functions exported by Storm.dll  typedef LCID  (WINAPI * SFILESET
逍遥剑客
2018/05/23
6740
Golang: Functions
Reader of this blog is assumed to have some basic programming skills. So in this series, we will not get into basic things like how function works. Because it’s basically the same for every languages, including Go.
Miigon
2022/10/27
1700
使用Google Cloud Platform进行资产跟踪
高价值资产往往会被放错地方或被盗。我们回顾了Leverege如何使用GCP创建一个使用物联网设备的资产跟踪解决方案。
用户4122690
2020/06/18
2.6K0
使用Google Cloud Platform进行资产跟踪
(译)Google Cloud Run 一瞥
Google 在 Cloud Next’19 上发布了基于 Docker 容器的的 Serverless 新方案。目前可以肯定的是,这是 Serverless 的重要进步——在 Cloud Run 上进行部署比在 Kubernetes 上运行容器简单多了。而且和 Lambda 不同,这一方案没有语言绑定的问题。
崔秀龙
2019/07/23
2.5K0
(译)Google Cloud Run 一瞥
Cloud Pilot 2.5 Google Cloud Platform 虚拟机迁移(下)
本周赶上独立日休假,本来没打算写。后来看了看上周的素材还多了点边角料,就顺手凑了一篇。实属为了这点醋,包了顿饺子。
s09g
2022/12/18
7720
Cloud Pilot 2.5 Google Cloud Platform 虚拟机迁移(下)
google cloud :穷人也能玩深度学习
本文介绍了如何使用Google Cloud Platform进行深度学习训练和部署。作者首先介绍了Google Cloud Platform的特点和优势,然后详细讲解了如何利用TensorFlow和Keras在Google Cloud Platform上部署和训练深度学习模型。作者还通过一个实际的案例演示了如何使用Google Cloud Platform进行训练和部署深度学习模型,并分享了在使用过程中需要注意的一些重要细节。
张鹏宇
2017/09/28
19K0
google cloud :穷人也能玩深度学习
【TypeScript】:functions、types
本系列文章将从一些著名开源项目中找一些 TypeScript 代码,讲解如何应用 TypeScript。
WEBJ2EE
2021/02/26
8660
【TypeScript】:functions、types

相似问题

Google Cloud Endpoint with Google Cloud Functions

20

来自Google Cloud Function的未处理拒绝

10

Google Cloud CDN接入Google Cloud Functions

124

部署Google Cloud Functions

24

Google Cloud Functions中的Express

117
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档