I am trying to do a Cloud Function that calls a request to the url passed to it. I have never used typescript to make a request, so I added some print calls in order to see if the axios could be the issue but the first log never appears in the Cloud Console. So I have no idea what is wrong and need some help. Can you please tell me why is my function not working, or not running at all?
Cloud Function [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;
// }
});
I tried both with the commented code and without. All I need is a cloud function that will make a request regardless of it using Axios or not.
Cloud Console log
requestFromServer
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{},"authenticationInfo":{"principalEmail":"[email protected]"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/shipping0110/locations/us-central1/functions/requestFromServer"}
Calling cloud function in app [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;
}
}
}
Console Error in 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