Skip to content

Commit

Permalink
Merge pull request #594 from Swastik19Nit/fix/error-handling-toast
Browse files Browse the repository at this point in the history
fix: "Cannot read properties of undefined (reading '__esModule')" Error
  • Loading branch information
jvJUCA authored Feb 20, 2025
2 parents 76e04a0 + dd1344d commit 2b0e31b
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions src/components/atoms/GlobalErrorHandler.vue
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
<template>
<div>
<Toast position="top-right" auto-close="{3000}" :render="error()" />
</div>
<div />
</template>

<script>
import Toast from 'vue-toastification'
import 'vue-toastification/dist/index.css'
import { mapState, mapMutations } from 'vuex'
export default {
components: { Toast },
data() {
return {
previousErrorMessage: '',
previousErrorCode: '',
}
},
computed: {
isError() {
return (
this.$store.state.error.message || this.$store.state.error.errorCode
)
},
...mapState({
error: (state) => state.error,
}),
},
methods: {
error() {
const mainError = this.$store.state.error
if (mainError && (mainError.message || mainError.errorCode)) {
watch: {
error: {
immediate: true,
deep: true,
handler(newError) {
if (
this.previousErrorMessage !== mainError.message ||
this.previousErrorCode !== mainError.errorCode
newError &&
(newError.message || newError.errorCode) &&
(newError.message !== this.previousErrorMessage ||
newError.errorCode !== this.previousErrorCode)
) {
this.$toast.error(`${mainError.errorCode}: ${mainError.message}`)
this.previousErrorMessage = ''
this.previousErrorCode = ''
this.$toast.error(`${newError.errorCode}: ${newError.message}`)
this.previousErrorMessage = newError.message
this.previousErrorCode = newError.errorCode
this.clearError()
}
this.$store.state.error.errorCode = ''
this.$store.state.error.message = ''
}
},
},
},
methods: {
...mapMutations(['clearError']),
},
}
</script>
</script>

0 comments on commit 2b0e31b

Please sign in to comment.