Skip to content

Commit

Permalink
fix: null data checks (#120)
Browse files Browse the repository at this point in the history
* fix: null data checks

* fix: null data checks

* Fixed issue #120 without logs
  • Loading branch information
Chaitanya674 authored Mar 6, 2024
1 parent 6b03757 commit 43c97ae
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
35 changes: 27 additions & 8 deletions pages/contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@ function Contributors({ contributors }) {
}

export const getStaticProps = async () => {
const data = await getContributors();

return {
props: {
contributors: data,
},
revalidate: 30,
};
try {
const data = await getContributors();
if (data.error) {
return {
props: {
contributors: [],
error: 'Error fetching contributors',
},
revalidate: 30,
};
}
return {
props: {
contributors: data,
error: null,
},
revalidate: 30,
};
} catch (error) {
return {
props: {
contributors: [],
error: 'server error',
},
revalidate: 30,
};
}
};

export default Contributors;
34 changes: 27 additions & 7 deletions pages/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@ function Solutions({ solutions }) {
}

export const getStaticProps = async () => {
const data = await getSolutions();
return {
props: {
solutions: data,
},
revalidate: 30,
};
try {
const data = await getSolutions();
if (data.error) {
return {
props: {
solutions: [],
error: 'Error fetching solutions',
},
revalidate: 30,
};
}
return {
props: {
solutions: data,
error: null,
},
revalidate: 30,
};
} catch (error) {
return {
props: {
solutions: [],
error: 'Server error',
},
revalidate: 30,
};
}
};

export default Solutions;
10 changes: 10 additions & 0 deletions utils/contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ const getContributors = async () => {
},
};
const data = await notion.request(payload);

if (!data || !data.results || data.results.length === 0) {
return { contributors: [], error: null };
}

const solutionsDBId = data.results[0].id;
payload = {
path: `databases/${solutionsDBId}/query`,
method: 'POST',
};
let { results } = await notion.request(payload);

if (!results || results.length === 0) {
return { contributors: [], error: null };
}

results = results.map((result) => ({
id: result.id,
name: result.properties.Name.title[0].text.content,
Expand Down
10 changes: 10 additions & 0 deletions utils/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ const getSolutions = async () => {
},
};
const data = await notion.request(payload);

if (!data || !data.results || data.results.length === 0) {
return { solutions: [], error: null };
}

const solutionsDBId = data.results[0].id;
payload = {
path: `databases/${solutionsDBId}/query`,
method: 'POST',
};
let { results } = await notion.request(payload);

if (!results || results.length === 0) {
return { solutions: [], error: null };
}

results = results.map((result) => ({
id: result.id,
title: result.properties.Name.title[0].text.content,
Expand Down

0 comments on commit 43c97ae

Please sign in to comment.