I am currently working on deploying an API for my application. However, when using the following code snippet, I encountered an unhandled error stating "Error: Data cannot be encoded in JSON."
const functions = require("firebase-functions");
const axios = require("axios");
exports.getDatas = functions.https.onCall(async (d)=>{
functions.logger.log(d["name"]);
cname = d["name"];
ts1=d["ts1"];
ts2=d["ts2"];
const data = await axios.get(
"https://api.coingecko.com/api/v3/coins/" +
cname +
"/market_chart/range?vs_currency=usd&from=" +
ts1 +
"&to=" +
ts2,
);
functions.logger.log(data);
return {data: data};
});
The error log generated is as follows:
Unhandled error Error: Data cannot be encoded in JSON: function httpAdapter(config) {
// The rest of the error log...
The first logger correctly logs the parameter passed, while the second logger that logs the data has a format like this:
...[{"api.coingecko.com:443::::::::::::::::::"}]
// The rest of the data log...
Although the code successfully logs the data, I'm facing challenges with returning it at the end. Can someone provide assistance?