Skip to content

Commit

Permalink
Refactor getRepoDescription function to handle failed API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Kwan committed Jan 10, 2024
1 parent 0a4d760 commit 80a1dd1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pages/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import ProjectCard from '../components/ProjectCard';

const github_pat = process.env.GITHUB_PAT;

const loadingMessage =
'Failed to fetch GitHub Repository description. Please try again later.';
// const projectsWithDescriptions = [''];

async function getRepoDescription(githubRepoUrl: string) {
const [, owner, repo] = new URL(githubRepoUrl).pathname.split('/');
try {
Expand All @@ -17,7 +21,7 @@ async function getRepoDescription(githubRepoUrl: string) {
}
);
const data = await response.json();
return data.description;
return data.description || loadingMessage;
} catch (error) {
console.error(`Error: ${error}`);
return 'Error: Could not fetch GitHub Repository description. Please try again later.';
Expand All @@ -41,10 +45,6 @@ const projectsWithDescriptions = [
'Arkanoid',
];

const loadingMessage =
'Failed to fetch GitHub Repository description. Please try again later.';
// const projectsWithDescriptions = [''];

function LoadingCard() {
return (
<div className="flex items-center justify-center p-4">
Expand Down

0 comments on commit 80a1dd1

Please sign in to comment.