feat: error response interceptor
This commit is contained in:
parent
a27dda4300
commit
3a310ef9db
3 changed files with 88 additions and 0 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import axios from 'axios'
|
||||
import { getToken } from './KeyCloakService'
|
||||
import { useErrorStore } from '@/stores/error'
|
||||
|
||||
const error = useErrorStore()
|
||||
|
||||
const instance = axios.create()
|
||||
|
||||
|
|
@ -8,4 +11,22 @@ instance.interceptors.request.use(async (config) => {
|
|||
return config
|
||||
})
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
const status = err.response.status
|
||||
const data = err.response.data
|
||||
|
||||
error.title = 'เกิดข้อผิดพลาด'
|
||||
|
||||
if (status === 500) {
|
||||
error.msg = 'เกิดข้อผิดพลาด ไม่สามารถดำเนินการต่อได้ กรุณาลองใหม่อีกครั้ง'
|
||||
} else {
|
||||
error.msg = data.message
|
||||
}
|
||||
|
||||
error.show()
|
||||
},
|
||||
)
|
||||
|
||||
export default instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue