Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NayamAmarshe opened this issue Mar 12, 2025 · 4 comments

Comments

@NayamAmarshe
Copy link

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;
@NayamAmarshe NayamAmarshe added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Mar 12, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added Repro Needed api: functions needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Mar 12, 2025
@DellaBitta
Copy link
Contributor

DellaBitta commented Mar 12, 2025

Hi @NayamAmarshe,

I think the issue might be in format of the error response. The object should include an error field:

response.status(400).send({
  error: {
    status: 'THIS_IS_NOT_VALID',
    message: 'this should be ignored'
  }
});

I just tested this format on one of our test functions and it worked as intended. I hope this helps!

@google-oss-bot
Copy link
Contributor

Hey @NayamAmarshe. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@NayamAmarshe if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants