Skip to content

Commit

Permalink
Merge pull request #507 from pycontw/fix/ssg-failed-due-to-api-error
Browse files Browse the repository at this point in the history
fix: prevent generation failed due to 4xx, 5xx api error
  • Loading branch information
josix authored Apr 11, 2024
2 parents ec333f3 + 1d1515a commit 16c84b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
34 changes: 26 additions & 8 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,30 @@ export default {
authorization: `Token ${process.env.AUTH_TOKEN}`,
},
}
const talks = await axios.get(
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=talk,sponsored`,
config,
)
const tutorials = await axios.get(
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=tutorial`,
config,
)
const talks = await axios
.get(
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=talk,sponsored`,
config,
)
.catch((error) => {
if (error.response.status === 404) {
return { data: [] }
}
})
const tutorials = await axios
.get(
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=tutorial`,
config,
)
.catch((error) => {
if (error.response.status === 404) {
return { data: [] }
}
})
const getAllDetailTalks = async () => {
if (!talks.data) {
return []
}
const data = await Promise.all(
talks.data.map(async (talk) => {
return await axios
Expand All @@ -34,6 +49,9 @@ export default {
return data
}
const getAllDetailTutorials = async () => {
if (!tutorials.data) {
return []
}
const data = await Promise.all(
tutorials.data.map(async (tutorial) => {
return await axios
Expand Down
1 change: 1 addition & 0 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const actions = {
},
async $getSchedulesData({ commit }) {
const { data } = await this.$http.$get('/api/events/schedule/')
if (!data) return
commit('setSchedulesData', data)
},
async $getKeynotesData({ commit }) {
Expand Down

0 comments on commit 16c84b0

Please sign in to comment.