summaryrefslogtreecommitdiffstats
path: root/src/services/NotifyErrorService.js
blob: 465b908b94d7b4c5f858518c9bc4d1c305dc67a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Vue from 'vue'
import router from '@/router/index.js'
import store from "@/store/index.js"


const error_notify = (error) => {
    if(error.response.status === 401) {
        Vue.notify({
            type: 'error',
            title: 'Please login again!',
            text: 'Token expire'
        })

        store.dispatch('logout')
        router.push('/login')
    }
    else
        for (const [key, values] of Object.entries(error.response.data)) {
            console.log(values)
            values.forEach(value => {
                Vue.notify({
                    type: 'error',
                    title: value,
                    text: (key !== 'non_field_errors') ? key : ''
                })
            })
        }

    return {
        data: error.response.data,
        status: error.response.status
    }
}

export default error_notify