auth/runtime config, URLs centralizados, parsing/hardening dos hooks/charts
This commit is contained in:
@@ -4,8 +4,9 @@ import type {
|
||||
WorkspaceChartPoint,
|
||||
WorkspaceChartTimeRange,
|
||||
} from "../../../components/charts/WorkspaceChart";
|
||||
|
||||
const BACKEND_URL = "http://localhost:18450";
|
||||
import { authFetch } from "../../../lib/api/authFetch";
|
||||
import { getBackendApiUrl } from "../../../lib/api/gatewayConfig";
|
||||
import { readOptionalJsonResponse } from "../../../lib/api/readJsonResponse";
|
||||
|
||||
type HistorianPoint = {
|
||||
timestamp: string;
|
||||
@@ -54,16 +55,16 @@ export function useClimateChartSeries(
|
||||
to: to.toISOString(),
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/historian/series?${params.toString()}`,
|
||||
const response = await authFetch(
|
||||
getBackendApiUrl(`/api/historian/series?${params.toString()}`),
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load climate history for ${key}`);
|
||||
}
|
||||
|
||||
const payload = (await response.json()) as HistorianPoint[];
|
||||
const payload = await readOptionalJsonResponse<HistorianPoint[]>(
|
||||
response,
|
||||
`Failed to load climate history for ${key}`,
|
||||
[],
|
||||
);
|
||||
|
||||
const points = payload
|
||||
.filter(
|
||||
@@ -130,4 +131,4 @@ function rangeToMs(range: WorkspaceChartTimeRange) {
|
||||
case "30d":
|
||||
return 30 * 24 * 60 * 60 * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user