Updates on errors

pull/144/head
Henrique Dias 2017-07-08 11:51:24 +01:00
parent 5eab62e0aa
commit c206bea84a
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
9 changed files with 86 additions and 18 deletions

View File

@ -112,7 +112,6 @@ export default {
api.put(this.$route.path, content) api.put(this.$route.path, content)
.then(() => { .then(() => {
buttons.done('save') buttons.done('save')
console.log('Saved!')
}) })
.catch(error => { .catch(error => {
buttons.done('save') buttons.done('save')

View File

@ -1,17 +1,8 @@
<template> <template>
<div v-if="error"> <div v-if="error">
<h2 class="message" v-if="error === 404"> <not-found v-if="error === 404"></not-found>
<i class="material-icons">gps_off</i> <forbidden v-else-if="error === 403"></forbidden>
<span>This location can't be reached.</span> <internal-error v-else></internal-error>
</h2>
<h2 class="message" v-else-if="error === 403">
<i class="material-icons">error</i>
<span>You're not welcome here.</span>
</h2>
<h2 class="message" v-else>
<i class="material-icons">error_outline</i>
<span>Something really went wrong.</span>
</h2>
</div> </div>
<editor v-else-if="isEditor"></editor> <editor v-else-if="isEditor"></editor>
<listing :class="{ multiple }" v-else-if="isListing"></listing> <listing :class="{ multiple }" v-else-if="isListing"></listing>
@ -19,6 +10,9 @@
</template> </template>
<script> <script>
import Forbidden from './errors/403'
import NotFound from './errors/404'
import InternalError from './errors/500'
import Preview from './Preview' import Preview from './Preview'
import Listing from './Listing' import Listing from './Listing'
import Editor from './Editor' import Editor from './Editor'
@ -38,6 +32,9 @@ function updateColumnSizes () {
export default { export default {
name: 'files', name: 'files',
components: { components: {
Forbidden,
NotFound,
InternalError,
Preview, Preview,
Listing, Listing,
Editor Editor
@ -105,8 +102,14 @@ export default {
this.setLoading(false) this.setLoading(false)
}) })
.catch(error => { .catch(error => {
this.error = error
this.setLoading(false) this.setLoading(false)
if (typeof error === 'object') {
this.error = error.status
return
}
this.error = error
}) })
}, },
keyEvent (event) { keyEvent (event) {

View File

@ -0,0 +1,13 @@
<template>
<div>
<h2 class="message">
<i class="material-icons">error</i>
<span>You're not welcome here.</span>
</h2>
</div>
</template>
<script>
export default {name: 'forbidden'}
</script>

View File

@ -0,0 +1,13 @@
<template>
<div>
<h2 class="message">
<i class="material-icons">gps_off</i>
<span>This location can't be reached.</span>
</h2>
</div>
</template>
<script>
export default {name: 'not-found'}
</script>

View File

@ -0,0 +1,13 @@
<template>
<div>
<h2 class="message">
<i class="material-icons">error_outline</i>
<span>Something really went wrong.</span>
</h2>
</div>
</template>
<script>
export default {name: 'internal-error'}
</script>

View File

@ -6,6 +6,9 @@ import Files from '@/components/Files'
import Users from '@/components/Users' import Users from '@/components/Users'
import User from '@/components/User' import User from '@/components/User'
import Settings from '@/components/Settings' import Settings from '@/components/Settings'
import error403 from '@/components/errors/403'
import error404 from '@/components/errors/404'
import error500 from '@/components/errors/500'
import auth from '@/utils/auth.js' import auth from '@/utils/auth.js'
import store from '@/store' import store from '@/store'
@ -53,6 +56,21 @@ const router = new Router({
name: 'Settings', name: 'Settings',
component: Settings component: Settings
}, },
{
path: '/403',
name: 'Forbidden',
component: error403
},
{
path: '/404',
name: 'Not Found',
component: error404
},
{
path: '/500',
name: 'Internal Server Error',
component: error500
},
{ {
path: '/users', path: '/users',
name: 'Users', name: 'Users',

View File

@ -14,7 +14,13 @@ const mutations = {
}, },
showError: (state, value) => { showError: (state, value) => {
state.show = 'error' state.show = 'error'
if (typeof value !== 'object') {
state.showMessage = value state.showMessage = value
return
}
state.showMessage = value.message
}, },
setLoading: (state, value) => { state.loading = value }, setLoading: (state, value) => { state.loading = value },
setReload: (state, value) => { state.reload = value }, setReload: (state, value) => { state.reload = value },

View File

@ -24,7 +24,10 @@ function fetch (url) {
resolve(JSON.parse(request.responseText)) resolve(JSON.parse(request.responseText))
break break
default: default:
reject(request.responseText) reject({
message: request.responseText,
status: request.status
})
break break
} }
} }

View File

@ -13,7 +13,7 @@ function loading (button) {
el.classList.add('spin') el.classList.add('spin')
el.innerHTML = 'autorenew' el.innerHTML = 'autorenew'
el.style.opacity = 1 el.style.opacity = 1
}, 200) }, 0)
} }
function done (button, success = true) { function done (button, success = true) {
@ -30,7 +30,7 @@ function done (button, success = true) {
el.classList.remove('spin') el.classList.remove('spin')
el.innerHTML = el.dataset.icon el.innerHTML = el.dataset.icon
el.style.opacity = 1 el.style.opacity = 1
}, 200) }, 0)
} }
export default { export default {