Skip to content

Commit 66e65bd

Browse files
committed
Added 404 and Network Issue components and functionality
1 parent ee6945c commit 66e65bd

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

src/router.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import EventList from './views/EventList.vue'
55
import EventShow from './views/EventShow.vue'
66
import NProgress from 'nprogress'
77
import store from '@/store/store'
8+
import NotFound from './views/NotFound.vue'
9+
import NetworkIssue from './views/NetworkIssue.vue'
810

911
Vue.use(Router)
1012

@@ -28,11 +30,35 @@ const router = new Router({
2830
component: EventShow,
2931
props: true,
3032
beforeEnter(routeTo, routeFrom, next) {
31-
store.dispatch('event/fetchEvent', routeTo.params.id).then(event => {
32-
routeTo.params.event = event
33-
next()
34-
})
33+
store
34+
.dispatch('event/fetchEvent', routeTo.params.id)
35+
.then(event => {
36+
routeTo.params.event = event
37+
next()
38+
})
39+
.catch(error => {
40+
if (error.response && error.response.status == 404) {
41+
next({ name: '404', params: { resource: 'event' } })
42+
} else {
43+
next({ name: 'network-issue' })
44+
}
45+
})
3546
}
47+
},
48+
{
49+
path: '/404',
50+
name: '404',
51+
component: NotFound,
52+
props: true
53+
},
54+
{
55+
path: '/network-issue',
56+
name: 'network-issue',
57+
component: NetworkIssue
58+
},
59+
{
60+
path: '*',
61+
redirect: { name: '404', params: { resource: 'page' } }
3662
}
3763
]
3864
})

src/services/EventService.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const apiClient = axios.create({
66
headers: {
77
Accept: 'application/json',
88
'Content-Type': 'application/json'
9-
}
9+
},
10+
timeout: 10000
1011
})
1112

1213
export default {

src/store/modules/event.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const actions = {
5959
dispatch('notification/add', notification, { root: true })
6060
})
6161
},
62-
fetchEvent({ commit, getters, dispatch, state }, id) {
62+
fetchEvent({ commit, getters, state }, id) {
6363
if (id == state.event.id) {
6464
return state.event
6565
}
@@ -70,18 +70,10 @@ export const actions = {
7070
commit('SET_EVENT', event)
7171
return event
7272
} else {
73-
return EventService.getEvent(id)
74-
.then(response => {
75-
commit('SET_EVENT', response.data)
76-
return response.data
77-
})
78-
.catch(error => {
79-
const notification = {
80-
type: 'error',
81-
message: 'There was a problem fetching event: ' + error.message
82-
}
83-
dispatch('notification/add', notification, { root: true })
84-
})
73+
return EventService.getEvent(id).then(response => {
74+
commit('SET_EVENT', response.data)
75+
return response.data
76+
})
8577
}
8678
}
8779
}

src/views/NetworkIssue.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div>
3+
<h1>Uh-Oh!</h1>
4+
<h3>It looks like you're experiencing some network issues, please click the back button and try again.</h3>
5+
<router-link :to="{ name: 'event-list' }">Or go back to the home page</router-link>
6+
</div>
7+
</template>

src/views/NotFound.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>
3+
<h1>Oops!</h1>
4+
<h3>The {{ resource }} you're looking for is not here.</h3>
5+
<router-link :to="{ name: 'event-list' }">Back to the home page</router-link>
6+
</div>
7+
</template>
8+
<script>
9+
export default {
10+
props: {
11+
resource: {
12+
type: String,
13+
required: true
14+
}
15+
}
16+
}
17+
</script>

0 commit comments

Comments
 (0)