Added better notification handling

This commit is contained in:
konrad 2018-09-08 21:43:16 +02:00
parent 875e4ea6e6
commit 85a8296278
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 32 additions and 27 deletions

21
package-lock.json generated
View File

@ -1205,18 +1205,6 @@
"long": "^3.2.0" "long": "^3.2.0"
} }
}, },
"@websanova/vue-dot": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@websanova/vue-dot/-/vue-dot-0.1.1.tgz",
"integrity": "sha512-xOroPXFJPs8HpGWHgX4yAk7y7Fce+w7omnGUrzowMI9P5JWTFftE1uBXA5Pm+wdp8nK9E1vgV7gWWrh8llohNA==",
"dev": true
},
"@websanova/vue-env": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/@websanova/vue-env/-/vue-env-0.6.2.tgz",
"integrity": "sha512-ExigiAGJlr7C+U0Y2Y3MmCQ7lJIeMvAjnkzJ1b7X9xBTTUyJQ7M8ReLVZJREZcZx2+NGurpLJE/wJQgBpmn2XQ==",
"dev": true
},
"abbrev": { "abbrev": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -4031,12 +4019,6 @@
"is-obj": "^1.0.0" "is-obj": "^1.0.0"
} }
}, },
"dotenv": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.0.0.tgz",
"integrity": "sha512-FlWbnhgjtwD+uNLUGHbMykMOYQaTivdHEmYwAKFjn6GKe/CqY0fNae93ZHTd20snh9ZLr8mTzIL9m0APQ1pjQg==",
"dev": true
},
"duplexer": { "duplexer": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
@ -12491,7 +12473,8 @@
"vue-notification": { "vue-notification": {
"version": "1.3.13", "version": "1.3.13",
"resolved": "https://registry.npmjs.org/vue-notification/-/vue-notification-1.3.13.tgz", "resolved": "https://registry.npmjs.org/vue-notification/-/vue-notification-1.3.13.tgz",
"integrity": "sha512-GBCpsd+usRF2EhLWl2/rzNWErYnlo+HoKV7G0LL6c/Iy2eo2ikpwVXlDAUepOQaeq0hJoDu0oyUfhKBRL1AosA==" "integrity": "sha512-GBCpsd+usRF2EhLWl2/rzNWErYnlo+HoKV7G0LL6c/Iy2eo2ikpwVXlDAUepOQaeq0hJoDu0oyUfhKBRL1AosA==",
"dev": true
}, },
"vue-router": { "vue-router": {
"version": "3.0.1", "version": "3.0.1",

View File

@ -9,8 +9,7 @@
}, },
"dependencies": { "dependencies": {
"bulma": "^0.7.1", "bulma": "^0.7.1",
"vue": "^2.5.17", "vue": "^2.5.17"
"vue-notification": "^1.3.13"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "^3.0.1", "@vue/cli-plugin-babel": "^3.0.1",
@ -19,6 +18,7 @@
"axios": "^0.18.0", "axios": "^0.18.0",
"node-sass": "^4.9.3", "node-sass": "^4.9.3",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",
"vue-notification": "^1.3.13",
"vue-router": "^3.0.1", "vue-router": "^3.0.1",
"vue-template-compiler": "^2.5.17" "vue-template-compiler": "^2.5.17"
}, },

View File

@ -33,12 +33,14 @@
<router-view/> <router-view/>
</div> </div>
</div> </div>
<notifications position="bottom left" />
</div> </div>
</template> </template>
<script> <script>
import auth from './auth' import auth from './auth'
import {HTTP} from './http-common' import {HTTP} from './http-common'
import message from './message'
export default { export default {
name: 'app', name: 'app',
@ -78,20 +80,20 @@
this.$set(this.namespaces[n], 'lists', response.data) this.$set(this.namespaces[n], 'lists', response.data)
}) })
.catch(e => { .catch(e => {
this.loading = false this.handleError(e)
// eslint-disable-next-line
console.log(e)
}) })
} }
this.loading = false this.loading = false
}) })
.catch(e => { .catch(e => {
this.loading = false this.handleError(e)
// eslint-disable-next-line
console.log(e)
}) })
}, },
handleError(e) {
this.loading = false
message.error(e, this)
}
}, },
} }
</script> </script>

View File

@ -7,6 +7,10 @@ import '../node_modules/bulma/bulma.sass'
Vue.config.productionTip = false Vue.config.productionTip = false
// Notifications
import Notifications from 'vue-notification'
Vue.use(Notifications)
// Check the user's auth status when the app starts // Check the user's auth status when the app starts
auth.checkAuth() auth.checkAuth()

16
src/message/index.js Normal file
View 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
})
}
}