Firebase Web Client Rewrites The Error Message Returned By An Https.onRequest Function, How To Prevent That?

I can not retrieve the message I send back from an "https.onRequest" function. The firebase client rewrites the message based on the error code and I can not recover the originally sent body or JSON.

On Firebase Functions :

exports.auth = functions.https.onRequest( (request, response) => {
    cors(request, response, async () => {
        try {
            return response.status(200).json({
                    data: "Hello"

        } catch (error) {
            return response
                .send('User not activated')

All is ok if I analyze in the chrome development console the return of the request: Body (response.send) : "User not activated"

But on the front side

auth: function (email, password) {
    var register = firebaseFunctions.httpsCallable('auth');

    return register({
            email: email,
            password: password
        .then(async (result) => {
            // ...
        .catch((err) => {
            throw err

In my catch statement :

err.message > permission-denied
err.details > undefined
err.code > 403

I do not know how to recover the message that I sent "User not activated" and that would allow me to process a 403 error code more accurately: the user can not connect because it is not activated.

Thanks a lot !



You're mixing up callable and regular HTTP type functions. That's not going to work at all.

On your function side, you're declaring the function as a regular HTTP type function using the onRequest callback. This means you need to use an HTTP client library to access it.

On your client side, you're trying to invoke the function as a callable type function using the Functions client SDK. This requires that you declare your function using an onCall callback, not the onRequest callback that you're using now. Callables have a special protocol that's implemented by the client SDK.

The client and server have to match; right now they do not. If you want to use a callable function, follow all the instructions in the linked documentation. If you want a regular HTTP type function, you can't use Functions client SDK. You have to use some other HTTP client library.