Skip to content

Commit

Permalink
fix: handle no access to view analytics gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Feb 12, 2025
1 parent 56a7795 commit 84e2f22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions client/services/analytics.js → client/api/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const getAnalyticsData = async () => {
});

if (!response.ok) {
if (response.status === 403) {
return {
statusCode: 403,
error: response.statusText,
};
}

throw new Error('Failed to fetch analytics data');
}

Expand All @@ -44,6 +51,13 @@ const getStatistics = async () => {
});

if (!response.ok) {
if (response.status === 403) {
return {
statusCode: 403,
error: response.statusText,
};
}

throw new Error('Failed to fetch analytics data');
}

Expand Down
2 changes: 1 addition & 1 deletion client/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const createAppRouter = () => {
element={<Analytics />}
loader={async () => {
const { getAnalyticsData, getStatistics } = await import(
'./services/analytics'
'./api/analytics'
);

return await Promise.all([getAnalyticsData(), getStatistics()]);
Expand Down
10 changes: 10 additions & 0 deletions client/routes/account/analytics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ import {
XAxis,
YAxis,
} from 'recharts';
import ErrorBox from '../../components/error-box';

const Analytics = () => {
const { t } = useTranslation();
const [analyticsData, stats] = useLoaderData();

// Handle error cases
if (analyticsData?.statusCode === 403) {
return (
<div className="animate-fadeIn">
<ErrorBox message={analyticsData?.error} />
</div>
);
}

// Process data for path visualization
const pathCounts = analyticsData.reduce((acc, item) => {
acc[item.path] = (acc[item.path] || 0) + 1;
Expand Down

0 comments on commit 84e2f22

Please sign in to comment.