Skip to content

httpsCallable throws invalid-argument error when the response status is not 200 #8841

Open
@NayamAmarshe

Description

@NayamAmarshe

Operating System

macOS

Environment (if applicable)

Node.js 22, Firebase Functions 2, Next.js 14

Firebase SDK Version

11.4.0

Firebase SDK Product(s)

Functions

Project Tooling

I'm using Next.js 14 along with Firebase Functions emulator.

Detailed Problem Description

  • When calling an onRequest function from the client using httpsCallable, it should return the correct response back.
  • From the functions side, if we return a response message, it should be parsable by the client.
  • However, when the status code is anything other than 200, the httpsCallable directly throws an invalid-argument error.
Unhandled Runtime Error
FirebaseError: invalid-argument
Image Image Image

Steps and code to reproduce issue

function:

import { onRequest } from "firebase-functions/https";
import { logger } from "../lib/logger";

export type TestRequest = {
  status: string;
  message: string;
};

export const test = onRequest(
  {
    cors: true,
    timeoutSeconds: 60,
    region: ["us-central1"],
  },
  async (req, res) => {
    logger.info("createLink called!", { structuredData: true });
    console.log("🚀 => req.body:", req.body);
    res.status(400).send({
      status: "error",
      message: "Missing required fields",
    });
  },
);

client:

import { functions } from "@/lib/firebase/firebase";
import { httpsCallable } from "firebase/functions";
import React from "react";

const TestPage = () => {
  const test = async () => {
    const createLink = httpsCallable(functions, "test");
    const response = await createLink();
    console.log(response);
  };
  return <button onClick={() => test()}>Test</button>;
};

export default TestPage;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions