Skip to content

Commit

Permalink
Check response status for usage queries
Browse files Browse the repository at this point in the history
Related to #374
  • Loading branch information
lbarcziova committed Feb 15, 2024
1 parent b8b12ad commit 37057e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion frontend/src/app/Usage/UsageInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const fetchDataByGranularity = (granularity: UsageIntervalProps) =>
`${import.meta.env.VITE_API_URL}/usage/intervals?days=${
granularity.days
}&hours=${granularity.hours}&count=${granularity.count}`,
).then((response) => response.json());
).then((response) => {
if (!response.ok) {
throw Promise.reject(response);
}
return response.json();
});

interface UsageIntervalProps {
days: number;
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/app/Usage/UsageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { UsageListData } from "./UsageListData";

const fetchDataByGranularity = (granularity: UsageListProps["what"]) =>
fetch(`${import.meta.env.VITE_API_URL}/usage/${granularity}`).then(
(response) => response.json(),
(response) => {
if (!response.ok) {
throw Promise.reject(response);
}
return response.json();
},
);

interface UsageListProps {
Expand Down

0 comments on commit 37057e4

Please sign in to comment.