Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinvanschoren committed Feb 1, 2024
1 parent 282ac7f commit f5aa599
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 30 deletions.
33 changes: 15 additions & 18 deletions app/src/pages/d/[dataId].js
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,25 @@ const VersionChip = styled(Chip)`
// Loads the information about the dataset from ElasticSearch
// Also loads the translations for the page
export async function getStaticProps({ params, locale }) {
try {
// Fetch necessary data for the dataset page using params.dataId
const data = await getItem("data", params.dataId);
let data = null;
let error = null;

return {
props: {
data,
error: null, // No error occurred
...(await serverSideTranslations(locale)),
},
};
try {
data = await getItem("data", params.dataId);
} catch (error) {
console.error("Error in getStaticProps:", error);

return {
props: {
data: null, // No data due to error
error: "Server is not responding.",
...(await serverSideTranslations(locale)),
},
};
error = "Server is not responding.";
}

const translations = await serverSideTranslations(locale);

return {
props: {
data,
error,
...translations,
},
};
}

const ActionButtons = ({ buttons }) => {
Expand Down
17 changes: 13 additions & 4 deletions app/src/pages/f/[flowId].js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ export async function getStaticPaths() {
}

export async function getStaticProps({ params, locale }) {
// Fetch necessary data for the flow page using params.flowId
const data = await getItem("flow", params.flowId);
let data = null;
let error = null;

try {
data = await getItem("flow", params.flowId);
} catch (error) {
console.error("Error in getStaticProps:", error);
error = "Server is not responding.";
}

const translations = await serverSideTranslations(locale);

return {
props: {
data,
// pass the translation props to the page component
...(await serverSideTranslations(locale)),
error,
...translations,
},
};
}
Expand Down
18 changes: 14 additions & 4 deletions app/src/pages/r/[runId].js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ export async function getStaticPaths() {
}

export async function getStaticProps({ params, locale }) {
// Fetch necessary data for the dataset page using params.dataId
const data = await getItem("run", params.runId);
let data = null;
let error = null;

try {
data = await getItem("run", params.runId);
} catch (error) {
console.error("Error in getStaticProps:", error);
error = "Server is not responding.";
}

const translations = await serverSideTranslations(locale);

return {
props: {
data,
// pass the translation props to the page component
...(await serverSideTranslations(locale)),
error,
...translations,
},
};
}
Expand Down
18 changes: 14 additions & 4 deletions app/src/pages/t/[taskId].js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ export async function getStaticPaths() {
}

export async function getStaticProps({ params, locale }) {
// Fetch necessary data for the task page using params.dataId
const data = await getItem("task", params.taskId);
let data = null;
let error = null;

try {
data = await getItem("task", params.taskId);
} catch (error) {
console.error("Error in getStaticProps:", error);
error = "Server is not responding.";
}

const translations = await serverSideTranslations(locale);

return {
props: {
data,
// pass the translation props to the page component
...(await serverSideTranslations(locale)),
error,
...translations,
},
};
}
Expand Down

0 comments on commit f5aa599

Please sign in to comment.