Node.js 忽略云函数中已完成函数的异常

Node.js 忽略云函数中已完成函数的异常,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,我正在使用Firebase的云函数来获取访问令牌,之后我将执行rest调用。但在执行此操作时,我得到了忽略已完成函数异常的异常 我想知道为什么我会收到这个信息,以及背后的原因是什么#AskFirebase 已编辑 下面是我的accessTokenHandler.js const functions = require('firebase-functions'); var googleAuth = require('google-oauth-jwt'); const predictor=r

我正在使用Firebase的云函数来获取访问令牌,之后我将执行rest调用。但在执行此操作时,我得到了忽略已完成函数异常的异常

我想知道为什么我会收到这个信息,以及背后的原因是什么#AskFirebase

已编辑 下面是我的accessTokenHandler.js

 const functions = require('firebase-functions');
 var googleAuth = require('google-oauth-jwt');
 const predictor=require("../prediction/predictor");


module.exports.getAccessToken=() =>{

googleAuth.authenticate({
email: 'my.gserviceaccount.com',
keyFile: "./accesstoken/key2.pem",
expiration: 3600000,
scopes: ['https://www.googleapis.com/auth/cloud-platform']
}, function (err, token) {
if(token){
    console.log("token:"+token);
    predictor.predict(token);
}
 if(err)console.log("err:"+err);
});
}
下面是我的predictor.js

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

module.exports.predict=(accessToken) =>{
predictImage(accessToken);
}

function predictImage(accessToken){

var httpRequest= new XMLHttpRequest();
httpRequest.open("POST","url",true);
httpRequest.setRequestHeader("Content-Type","application/json");
httpRequest.setRequestHeader("Accept","application/json");
httpRequest.setRequestHeader("Authorization", "Bearer " + accessToken); 
httpRequest.send(getRequestJson());

httpRequest.onreadystatechange =function(){
    if(this.readyState==4){
    console.log("status:"+this.status+" state:"+this.readyState)
    console.log("response:"+this.responseText)
    }
}
}

function getRequestJson()
{
var b64Image='/9j/oAxt--encoded---f/2Q==';
var requestJson={"instances":
[{"key":"input_cloudfunction.jpg","image_bytes":{"b64":b64Image}}]};
return requestJson;
}
还有我的index.js文件

const functions = require('firebase-functions');

exports.handleFreshAccessToken = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!"); 
 const accessHandler=require("./accesstoken/accesstoken_handler");
 return accessHandler.getAccessToken();
});

代码在完成之前发生了一些错误。对于HTTPS类型的函数,它们在向客户端发送响应时正式完成。在您的代码中,您将立即向客户机发送响应,这意味着您在此之后所做的一切都是在“函数完成后”发生的


如果要在函数中执行异步工作,则应等待所有工作完成(使用承诺),然后再发送响应。

显然,来自异步函数的未捕获异常在云函数框架中。 解决方案是用
try{}catch
块包围代码,异步代码用
wait
块,并在catch块中记录所有异常

例如:

async function ()
{
    try
    {
        // throws exception
        await SomeFunc ()
    }
    catch (e)
    {
        console.log ('error: ' + e)
    }
}

请显示函数的代码。@DougStevenson请看,我已经用代码编辑了我的问题。生成错误的函数名以“handleFresh”开头,但在您提供的代码中,我没有看到名为“handleFresh”的云函数。是的,因为它是index.js。。。。让我告诉你,我已经添加了我的index.js代码。关于后台函数,你如何知道异常详细信息?