Improved error messaging for project retrieval

dependabot/npm_and_yarn/typescript-eslint/parser-4.33.0
guusvanmeerveld 3 years ago
parent 2b70793099
commit 68e9bca751

@ -1 +1 @@
API_ENDPOINT=cdn.guusvanmeerveld.dev CDN_ENDPOINT=cdn.guusvanmeerveld.dev

@ -8,9 +8,9 @@ const { i18n } = require('./next-i18next.config');
module.exports = { module.exports = {
i18n, i18n,
images: { images: {
domains: [process.env.API_ENDPOINT], domains: [process.env.CDN_ENDPOINT],
}, },
env: { env: {
API_ENDPOINT: process.env.API_ENDPOINT, CDN_ENDPOINT: process.env.CDN_ENDPOINT,
}, },
}; };

@ -11,6 +11,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.4", "axios": "^0.21.4",
"chalk": "^4.1.2",
"milligram": "^1.4.1", "milligram": "^1.4.1",
"next": "^11.1.2", "next": "^11.1.2",
"next-i18next": "^8.8.0", "next-i18next": "^8.8.0",

@ -28,7 +28,7 @@ const Project: FC<ProjectComponent> = ({ name, description, buttons, cover, righ
{cover ? ( {cover ? (
<div className={styles.cover}> <div className={styles.cover}>
<Image <Image
src={`https://${process.env.API_ENDPOINT}/portfolio/${cover}`} src={`https://${process.env.CDN_ENDPOINT}/portfolio/${cover}`}
width={200} width={200}
height={200} height={200}
alt={name} alt={name}

@ -1,6 +1,7 @@
import { GetStaticProps, NextPage } from 'next'; import { GetStaticProps, NextPage } from 'next';
import axios from 'axios'; import axios, { AxiosError } from 'axios';
import chalk from 'chalk';
import Image from 'next/image'; import Image from 'next/image';
@ -54,16 +55,36 @@ const Home: NextPage<{ projects: ProjectModel[] }> = ({ projects }) => {
}; };
export const getStaticProps: GetStaticProps = async ({ locale }) => { export const getStaticProps: GetStaticProps = async ({ locale }) => {
const { data: projects } = await axios( const translation = await serverSideTranslations(locale, ['home', 'nav']);
`https://${process.env.API_ENDPOINT}/portfolio/projects-${locale}.json`
const projects: ProjectModel[] | undefined = await axios(
`https://${process.env.CDN_ENDPOINT}/portfolio/projects-${locale}.json`
)
.then(({ data }) => {
console.log(
chalk`{magenta event} - retrieved projects from ` +
process.env.CDN_ENDPOINT +
' successfully'
); );
return data;
})
.catch((error: AxiosError) => {
console.log(chalk`{red error} - failed to retrieve projects:`);
console.log(error.message);
});
if (projects) {
return { return {
props: { props: {
...(await serverSideTranslations(locale, ['home', 'nav'])), ...translation,
projects, projects,
}, },
}; };
}
throw new Error('Failed to retrieve projects from ' + process.env.CDN_ENDPOINT);
}; };
export default Home; export default Home;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save