Skip to content

Commit

Permalink
New list-projects.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rN834 authored Jan 25, 2025
1 parent 4b7149d commit 990cab5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions extensions/capmo/src/list-projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ export default function ListProjects() {
isLoading,
error,
} = useCachedPromise(async () => {
const token = getCapmoToken();
const response = await axios.get<{ data: { items: Project[] } }>(
"https://api.capmo.de/api/v1/projects",
{
headers: { Authorization: token },
},
);
try {
const token = getCapmoToken();
const response = await axios.get<{ data: { items: Project[] } }>(
"https://api.capmo.de/api/v1/projects",
{
headers: { Authorization: token },
}
);

// Validate and filter projects
const projectItems = response.data?.data?.items;
if (projectItems && Array.isArray(projectItems)) {
return projectItems.filter((project) => !project.is_archived);
} else {
throw new Error("Unexpected response format for projects.");
// Validate and filter projects
const projectItems = response.data?.data?.items;
if (Array.isArray(projectItems)) {
return projectItems.filter((project) => !project.is_archived);
} else {
throw new Error("Unexpected response format for projects.");
}
} catch (err) {
throw new Error(
err instanceof Error ? err.message : "Failed to fetch projects."
);
}
});

Expand Down

0 comments on commit 990cab5

Please sign in to comment.