Hono client issues with newrelic?
Guys, I almost gave up.. I cant solve the issue:
- I added newrelic for monitoring
- All my endpoints goes to 401 Unauthorized
I started to debug and im using hono with react query:
So basically this one not works If I start my app with newrelic:
import { client } from "@/lib/hono";
import { useQuery } from "@tanstack/react-query";
import { TrackedTimeResponse } from "@/features/statistics/types";
export const useGetTrackedTime = () => {
return useQuery<TrackedTimeResponse, Error>({
queryKey: ["get-tracked-time"],
queryFn: async () => {
try {
const response = await client.api.statistics["get-tracked-time"].$get();
if (!response.ok) {
throw new Error(
return data; } catch (error) { console.error("Error in useGetTrackedTime:", error); throw error; } }, }); }; But.. If I remove hono client and just make simple fetch (or even If I try this endpoint on my browser): export const useGetTrackedTime = () => { return useQuery<TrackedTimeResponse, Error>({ queryKey: ["get-tracked-time"], queryFn: async () => { try { const response = await fetch('/api/statistics/get-tracked-time'); if (!response.ok) { throw new Error('Failed to fetch data'); } return response.json(); } catch (error) { throw error; } }, }); }; It works and returns 200. Any have anything similar? Any recommendations?
API Error: ${response.status} ${response.statusText}
);
}
const data = await response.json();
return data; } catch (error) { console.error("Error in useGetTrackedTime:", error); throw error; } }, }); }; But.. If I remove hono client and just make simple fetch (or even If I try this endpoint on my browser): export const useGetTrackedTime = () => { return useQuery<TrackedTimeResponse, Error>({ queryKey: ["get-tracked-time"], queryFn: async () => { try { const response = await fetch('/api/statistics/get-tracked-time'); if (!response.ok) { throw new Error('Failed to fetch data'); } return response.json(); } catch (error) { throw error; } }, }); }; It works and returns 200. Any have anything similar? Any recommendations?
2 Replies
Did you checked your network tab on how the requests were going into the server? Was there any changes in headers, payload, etc. when you sent it from
hc
or fetch
?
Can you share a screenshot from your network tab when sending those requests?Aditya thanks! I was blind and tried look from around... checked the headers and the problem that newrelic node options loads .env not .env.local even doing next dev... And HC loads url from vars.. So thank you!! 🙂