Skip to content

Commit

Permalink
feat: add custom error page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Pennec committed Nov 5, 2018
1 parent 25c5cab commit 65d2279
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions layouts/error.vue
@@ -0,0 +1,27 @@
<template>
<div class="container">
<h3 v-if="error.customMessage">{{ error.customMessage }}</h3>
<h3 v-else-if="error.statusCode === 404">Page not found...</h3>
<h3 v-else>Sorry, an error occurred :-(</h3>
<nuxt-link to="/">Back to the home page</nuxt-link>
</div>
</template>

<script>
export default {
props: {
error: {
type: Object
}
}
}
</script>

<style scoped>
.container {
text-align: center;
}
h3 {
padding: 10px 0 40px;
}
</style>
2 changes: 1 addition & 1 deletion pages/weather/_citycode.vue
Expand Up @@ -24,7 +24,7 @@ export default {
async asyncData ({ app, error, params, store }) {
const citycode = store.state.cities.find((city) => city.toLowerCase() === params.citycode)
if (!citycode) {
return error({ message: 'City not found', statusCode: 404 })
return error({ customMessage: `City « ${params.citycode} » not found...`, statusCode: 404 })
}
store.commit('SET_CITY', citycode.toLowerCase())
Expand Down

0 comments on commit 65d2279

Please sign in to comment.