Sam
Sam

Reputation: 3064

Firebase cloud functions throws timeout exception but standalone works fine

I am trying to call a third party API using my Firebase cloud functions. I have billing enabled and all my other function are working fine.

However, I have one method that throws Timeout exception when it tries to call third API. The interesting thing is, when I run the same method from a standalone nodeJS file, it works fine. But when I deploy it on Firebase cloud or start the function locally, it shows timeout error.

Following is my function:

exports.fetchDemo = functions.https.onRequest(async (req, response) => 
{
    var res = {};
    res.started = true;
    await myMethod();
    res.ended = true;
    response.status(200).json({ data: res });
});

async function myMethod() {
     var url = 'my third party URL';
     console.log('Line 1');
     const res = await fetch(url);
     console.log('Line 2'); // never prints when run with cloud functions
     var data = await res.text();
     console.log(`Line 3: ${data}`);
}

Just now I also noticed, when I hit the same URL in the browser it gives the following exception. It means, it works only with standalone node.

<errorDTO>
  <code>INTERNAL_SERVER_ERROR</code>
 <uid>c0bb83ab-233c-4fe4-9a9e-3f10063e129d</uid>
</errorDTO>

Any help will be appreciated...

Upvotes: 0

Views: 413

Answers (1)

Sam
Sam

Reputation: 3064

It turned out that one of my colleague wrote a new method with the name fetch. I was not aware about it. So when my method was calling to the fetch method, it was actually calling his method he wrote down the file. I just took git update and did not notice he wrote this method.

Upvotes: 1

Related Questions