Skip to content

Commit 5c88c46

Browse files
fix bug where reading value when server is offline could throw client error (#1154)
1 parent c48f418 commit 5c88c46

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

.changeset/short-peas-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
fix bug where reading value when server is offline could throw client error

packages/app/src/components/DBTimeChart.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,31 @@ function DBTimeChartComponent({
7575

7676
const { graphResults, timestampColumn, groupKeys, lineNames, lineColors } =
7777
useMemo(() => {
78-
return data != null && isSuccess
79-
? formatResponseForTimeChart({
80-
res: data,
81-
dateRange,
82-
granularity,
83-
generateEmptyBuckets: fillNulls !== false,
84-
source,
85-
})
86-
: {
87-
graphResults: [],
88-
timestampColumn: undefined,
89-
groupKeys: [],
90-
lineNames: [],
91-
lineColors: [],
92-
};
93-
}, [data, dateRange, granularity, isSuccess, fillNulls]);
78+
const defaultResponse = {
79+
graphResults: [],
80+
timestampColumn: undefined,
81+
groupKeys: [],
82+
lineNames: [],
83+
lineColors: [],
84+
};
85+
86+
if (data == null || !isSuccess) {
87+
return defaultResponse;
88+
}
89+
90+
try {
91+
return formatResponseForTimeChart({
92+
res: data,
93+
dateRange,
94+
granularity,
95+
generateEmptyBuckets: fillNulls !== false,
96+
source,
97+
});
98+
} catch (e) {
99+
console.error(e);
100+
return defaultResponse;
101+
}
102+
}, [data, dateRange, granularity, isSuccess, fillNulls, source]);
94103

95104
// To enable backward compatibility, allow non-controlled usage of displayType
96105
const [displayTypeLocal, setDisplayTypeLocal] = useState(displayTypeProp);

0 commit comments

Comments
 (0)