可调用的云函数未运行,调用时引发错误



我正在尝试执行一个云函数,该函数调用对传递给它的url的请求。我从未使用typescript进行请求,所以我添加了一些打印调用,以查看axios是否是问题所在,但第一个日志从未出现在云控制台中。所以我不知道出了什么问题,需要一些帮助。你能告诉我为什么我的功能不工作,或者根本不运行吗?

云功能〔Typescript〕

export const requestFromServer = functions.https.onCall(async (data)=> {
console.log("to create axios");
// try {
console.log("entering try/catch block");
const response = await axios.default.get(data as string);
console.log("response about to be returned");
console.log(response);
return response;
// } catch (e) {
//   console.log("error:");
//   console.log(e);
//   return null;
// }
});

我尝试了使用注释代码和不使用注释代码。我所需要的只是一个云功能,无论是否使用Axios,它都会发出请求。

云控制台日志

requestFromServer
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{},"authenticationInfo":{"principalEmail":"bryancoellobusiness@gmail.com"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/shipping0110/locations/us-central1/functions/requestFromServer"}

调用应用程序〔Dart〕中的云功能

class CloudFunctions {
static final _functions = FirebaseFunctions.instance;
Future requestFromServer(String url) async {
print('hey I was called');
try {
var response =
await _functions.httpsCallable('requestFromServer').call(url);
print('comessss back');
print('response.data: ${response}');
return response;
} catch (e) {
print(e.toString()); //error message below
return null;
}
}
}

VSCode 中的控制台错误

[firebase_functions/internal] internal
Error: NoSuchMethodError: 'data'
method not found
Reciever: null
Arguments: []
at Object.throw_ [as throw] (http://localhost:51782/dart_sdk.js:5069:11)
at Object.defaultNoSuchMethod (http://localhost:51782/dart_sdk.js:5503:15)
at Object.noSuchMethod (http://localhost:51782/dart_sdk.js:5499:27)
at Object.dload (http://localhost:51782/dart_sdk.js:5130:17)
at places_service.PlacesService.new.getAutoComplete (http://localhost:51782/packages/app/services/places_service.dart.lib.js:104:58)
at getAutoComplete.next (<anonymous>)
at http://localhost:51782/dart_sdk.js:40578:33
at _RootZone.runUnary (http://localhost:51782/dart_sdk.js:40448:59)
at _FutureListener.thenAwait.handleValue (http://localhost:51782/dart_sdk.js:35370:29)
at handleValueCallback (http://localhost:51782/dart_sdk.js:35938:49)
at Function._propagateToListeners (http://localhost:51782/dart_sdk.js:35976:17)
at _Future.new.[_completeError] (http://localhost:51782/dart_sdk.js:35830:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:51782/dart_sdk.js:35866:31)
hey I was called
[firebase_functions/internal] internal
Error: NoSuchMethodError: 'data'
method not found
at Object._microtaskLoop (http://localhost:51782/dart_sdk.js:40715:13)
at _startMicrotaskLoop (http://localhost:51782/dart_sdk.js:40721:13)
at http://localhost:51782/dart_sdk.js:36198:9

问题是我在Axios中导入了所有的东西,而不是只导入Axios

import * as axios from "axios"; //before
import axios from "axios";
export const serverRequest = functions.https.onCall(async (url, context)=> {
isAuthenticatedAdmin(context);
const response = await axios.get(url as string).then(({data})=> data);
return response;
});

相关内容

  • 没有找到相关文章

最新更新