The cloud function that is callable is currently inactive and encountering errors upon invocation

I am experiencing issues with my Cloud Function which is supposed to call a request to the URL passed to it. This is my first time using TypeScript to make a request, so I added some print calls to troubleshoot the problem. However, the first log never appears in the Cloud Console, leaving me confused about what could be wrong. Can someone please help me figure out why my function is not working or 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 have attempted running the function both with and without the commented code. All I need is a cloud function that can effectively make a request, regardless of whether it uses Axios or not.

Cloud Console log

requestFromServer
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{},"authenticationInfo":{"principalEmail":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcdecec5ddd2dfd3d9d0d0d3dec9cfd5d2d9cfcffcdbd1ddd5d092dfd3d1">[email protected]</a>"},"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

Answer №1

The problem was caused by importing all items from Axios instead of just importing 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;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

@ngrx effects ensure switchmap does not stop on error

Throughout the sign up process, I make 3 http calls: signing up with an auth provider, creating an account within the API, and then logging in. If the signup with the auth provider fails (e.g. due to an existing account), the process still tries to create ...

Pass data from a Firebase JavaScript callback function in the Data Access Layer (DAL) to another function in the controller

I have been developing a basic chat application that enables users to send messages in a group chat and see them instantly updated. To achieve this, I opted for Firebase and spent time familiarizing myself with its web API. However, I encountered difficult ...

Which option is more beneficial for intercepting API data in Angular 6: interfaces or classes?

My API returns JSON data that is not structured the way I need it, so I have to make changes. { "@odata.context":"xxxxxx", "id":"xxxxxxxx", "businessPhones":[ ], "displayName":"name", "givenName":"pseudo", "jobTitle":null, "ma ...

What reasons underlie the existence of various methods for importing Modules in JavaScript?

I'm confused about the distinctions when it comes to importing a JavaScript module in various ways such as: CommonJS ES5 ES6 NodeJS Typescript What is the reason for having multiple methods of importing JavaScript modules? Is the concept of a "modu ...

Intermittent issue with Angular 2 encountered while following the Hero Editor tutorial on angular.io

I am encountering an occasional error in the console while following the angular.io tutorial using Mozilla Firefox. The error does not seem to impact the functionality or rendering of my application, and it only happens sporadically. If you could provide ...

Unraveling the Mystery of @Input and @Output Aliases in Angular 2

After researching about the @Input() and @Output() decorators, I discovered that we have the option to use an alias instead of the property name for these decorators. For example: class ProductImage { //Aliased @Input('myProduct') pro ...

calculate the difference between two dates and then add this difference to a new date

Utilizing TypeScript for date calculations. Example: Initial Date 1: "10/06/2021 10:10:05" Initial Date 2: "08/06/2021 11:10:05" Calculate the difference between the two dates, including date/month/year/hour/min/sec/milliseconds. Ensure compatibility wi ...

Utilizing TypeScript for enhanced Chrome notifications

I am currently developing a Chrome app using TypeScript (Angular2) and I want to implement push notifications. Here is the code snippet for my notification service: import {Injectable} from 'angular2/core'; @Injectable() export class Notificati ...

An error occurred while attempting to set up Next-auth in the process of developing

In my Next.js app, I have implemented next-auth for authentication. During local development, everything works fine with 'npm install' and 'npm run dev', but when I try to build the project, I encounter this error message: ./node_modul ...

The typescript error "Cannot read properties of undefined" is encountered while trying to access the 'map' function

I was attempting to follow a guide on creating an app using typescript and react, but I'm encountering an error that says "Cannot read properties of undefined (reading 'map')". I'm not sure why this is happening, can someone please offe ...

Having difficulties viewing the sidemenu icon on Ionic 3, despite enabling the menu through MenuController

I am trying to show the sidemenu icon on my Home page, which users can access from the Add-Contract page. Even though I have enabled the sidemenu in home.ts using this.menu.enable(true);, the icon is not visible. However, I can still swipe and access the ...

The issue persists in VSCode where the closing brackets are not being automatically added despite

Recently, I've noticed that my vscode editor is failing to automatically add closing brackets/parenthesis as it should. This issue only started happening recently. I'm curious if anyone else out there has encountered this problem with their globa ...

Retrieving information from a JSON object in Angular using a specific key

After receiving JSON data from the server, I currently have a variable public checkId: any = 54 How can I extract the data corresponding to ID = 54 from the provided JSON below? I am specifically looking to extract the values associated with KEY 54 " ...

A TypeScript method for accessing deeply nested properties within an object

I'm currently working on a function that utilizes typings to extract values from a nested object. With the help of this post, I managed to set up the typing for two levels successfully. However, when I introduce a third (known) level between the exis ...

How can the values from the scale [-60, -30, -10, 0, 3, 6, 10] be converted to a decimal range of 0-1 through

Thank you for helping me with so many of my issues. <3 I'm certain that someone has already solved this, but I'm unsure of the specific mathematical term (I've attempted reverse interpolation and others, but with no luck) so I am present ...

Troubleshooting the issue with the HTTPClient get method error resolution

Currently, I am attempting to capture errors in the HTTP get request within my service file. Below is the code snippet: import { Injectable } from '@angular/core'; import { PortfolioEpicModel, PortfolioUpdateStatus } from '../models/portfol ...

Strange behavior of the .hasOwnProperty method

When attempting to instantiate Typescript objects from JSON data received over HTTP, I began considering using the for..in loop along with .hasOwnProperty(): class User { private name: string; private age: number; constructor(data: JSON) { ...

Guide on defining a data type for the response payload in a Next.js route controller

interface DefaultResponse<T> { success: boolean; message?: string; user?: T; } export async function POST(req: Request) { const body: Pick<User, 'email' | 'password'> = await req.json(); const user = await prisma ...

The specified class is not found in the type 'ILineOptions' for fabricjs

Attempting to incorporate the solution provided in this answer for typescript, , regarding creating a Line. The code snippet from the answer includes the following options: var line = new fabric.Line(points, { strokeWidth: 2, fill: '#999999', ...

Protractor enables horizontal scrolling for a Div element

My struggle to scroll to the right persists despite all attempts I experimented with various solutions, but none seem to work await browser.executeScript('arguments[0].scrollIntoView(true)',element.getWebElement()) The issue still remains unr ...