Add a little debugging to stocks endpoint

This commit is contained in:
shamoon 2024-12-15 19:15:27 -08:00
parent 93c18a8077
commit 0c352b1843

View File

@ -1,9 +1,14 @@
import cachedFetch from "utils/proxy/cached-fetch";
import { getSettings } from "utils/config/config";
import createLogger from "utils/logger";
const logger = createLogger("stocks");
export default async function handler(req, res) {
const { watchlist, provider, cache } = req.query;
logger.debug("Stocks API request: %o", { watchlist, provider, cache });
if (!watchlist) {
return res.status(400).json({ error: "Missing watchlist" });
}
@ -56,6 +61,7 @@ export default async function handler(req, res) {
// Finnhub free accounts allow up to 60 calls/minute
// https://finnhub.io/pricing
const { c, dp } = await cachedFetch(apiUrl, cache || 1);
logger.debug("Finnhub API response for %s: %o", ticker, { c, dp });
// API sometimes returns 200, but values returned are `null`
if (c === null || dp === null) {