0

I'm trying to send get requests through google cloud terminal. Get request is inside a map function so around 41 requests had to be made according to the 41 items. Unfortunately after 13 to 14 requests, it starts to throw this following error:

(node:363) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): FetchError: invalid json response body at http://project-vision-201106.appspot.com/fetch_ticker?pair=POWR/BTC reason: Unexpected token < in JSON at position 1

(node:363) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): FetchError: invalid json response body at http://project-vision-201106.appspot.com/fetch_ticker?pair=DNT/BTC reason: Unexpected token < in JSON at position 1

...

Upon a manual get request to the following pair is working like a charm. Is it the problem related to the timeout b/c of the limit or am I doing something wrong here?

Here is my code:

const calBTC = _.map(balance_final, (val, key) => {
            if (key === 'BTC') {
                allBTC.push(val);
            } else {
                return fetch(`http://project-vision-201106.appspot.com    /fetch_ticker?pair=${key}/BTC`).then(res => {
                    return res.json().then(res => {
                        console.log(res.close);
                        return res.close * val;
                    })
                }, error => {
                    return '000';
                })
            }
        });

Here is the request block:

app.get('/fetch_ticker', (req, res) => {
            (async () => {
                let pair = req.param('pair', "BTC/ETH");
                let ex = req.param('exchange', "coinmarketcap");
                let myArr = [];
                let exchange = new ccxt[ex]();
                let tickers = await exchange.fetchTicker(pair);

                myArr.push(tickers);

                //Send req
                res.status(200).send(tickers);
            })()
        });
Abrar A.
  • 113
  • 3
  • 11

0 Answers0