Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle cases where the flag name causes API errors (or other errors occur) #8439

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions frontend/src/component/personalDashboard/FlagMetricsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ const useFlagMetrics = (
environment: string | null,
hoursBack: number,
) => {
const { featureMetrics: metrics = [], loading } = useFeatureMetricsRaw(
flagName,
hoursBack,
);
const {
featureMetrics: metrics = [],
loading,
error,
} = useFeatureMetricsRaw(flagName, hoursBack);

const sortedMetrics = useMemo(() => {
return [...metrics].sort((metricA, metricB) => {
return metricA.timestamp.localeCompare(metricB.timestamp);
Expand All @@ -151,7 +153,7 @@ const useFlagMetrics = (
return createBarChartOptions(theme, hoursBack, locationSettings);
}, [theme, hoursBack, locationSettings]);

return { data, options, loading };
return { data, options, loading, error };
};

const EnvironmentSelect: FC<{
Expand Down Expand Up @@ -222,11 +224,22 @@ export const FlagMetricsChart: FC<{
const { environment, setEnvironment, activeEnvironments } =
useMetricsEnvironments(flag.project, flag.name);

const { data, options, loading } = useFlagMetrics(
flag.name,
environment,
hoursBack,
);
const {
data,
options,
loading,
error: metricsError,
} = useFlagMetrics(flag.name, environment, hoursBack);

if (metricsError) {
return (
<ChartContainer>
<PlaceholderFlagMetricsChart
label={`Couldn't fetch metrics for the current flag. This may be a transient error, or your flag name ("${flag.name}") may be causing issues.`}
/>
</ChartContainer>
);
}

const noData = data.datasets[0].data.length === 0;

Expand Down
Loading