Added better notification handling
This commit is contained in:
14
src/App.vue
14
src/App.vue
@ -33,12 +33,14 @@
|
||||
<router-view/>
|
||||
</div>
|
||||
</div>
|
||||
<notifications position="bottom left" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import auth from './auth'
|
||||
import {HTTP} from './http-common'
|
||||
import message from './message'
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
@ -78,20 +80,20 @@
|
||||
this.$set(this.namespaces[n], 'lists', response.data)
|
||||
})
|
||||
.catch(e => {
|
||||
this.loading = false
|
||||
// eslint-disable-next-line
|
||||
console.log(e)
|
||||
this.handleError(e)
|
||||
})
|
||||
}
|
||||
|
||||
this.loading = false
|
||||
})
|
||||
.catch(e => {
|
||||
this.loading = false
|
||||
// eslint-disable-next-line
|
||||
console.log(e)
|
||||
this.handleError(e)
|
||||
})
|
||||
},
|
||||
handleError(e) {
|
||||
this.loading = false
|
||||
message.error(e, this)
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -7,6 +7,10 @@ import '../node_modules/bulma/bulma.sass'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
// Notifications
|
||||
import Notifications from 'vue-notification'
|
||||
Vue.use(Notifications)
|
||||
|
||||
// Check the user's auth status when the app starts
|
||||
auth.checkAuth()
|
||||
|
||||
|
16
src/message/index.js
Normal file
16
src/message/index.js
Normal file
@ -0,0 +1,16 @@
|
||||
export default {
|
||||
error(e, context) {
|
||||
// Build the notification text from error response
|
||||
let err = e.message
|
||||
if (e.response && e.response.data && e.response.data.message) {
|
||||
err += '<br/>' + e.response.data.message
|
||||
}
|
||||
|
||||
// Fire a notification
|
||||
context.$notify({
|
||||
type: 'error',
|
||||
title: 'Error',
|
||||
text: err
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user