v6 update

This commit is contained in:
Mohit Panjwani
2022-01-10 16:06:17 +05:30
parent b770e6277f
commit bdea879273
722 changed files with 19047 additions and 9186 deletions

View File

@ -0,0 +1,78 @@
import { useAuthStore } from '@/scripts/customer/stores/auth'
import { useNotificationStore } from '@/scripts/stores/notification'
export const handleError = (err) => {
const authStore = useAuthStore()
const notificationStore = useNotificationStore()
if (!err.response) {
notificationStore.showNotification({
type: 'error',
message:
'Please check your internet connection or wait until servers are back online.',
})
} else {
if (
err.response.data &&
(err.response.statusText === 'Unauthorized' ||
err.response.data === ' Unauthorized.')
) {
// Unauthorized and log out
const msg = err.response.data.message
? err.response.data.message
: 'Unauthorized'
showToaster(msg)
authStore.logout()
} else if (err.response.data.errors) {
// Show a notification per error
const errors = JSON.parse(JSON.stringify(err.response.data.errors))
for (const i in errors) {
showError(errors[i][0])
}
} else if (err.response.data.error) {
showError(err.response.data.error)
} else {
showError(err.response.data.message)
}
}
}
export const showError = (error) => {
switch (error) {
case 'These credentials do not match our records.':
showToaster('errors.login_invalid_credentials')
break
case 'The email has already been taken.':
showToaster('validation.email_already_taken')
break
case 'invalid_credentials':
showToaster('errors.invalid_credentials')
break
case 'Email could not be sent to this email address.':
showToaster('errors.email_could_not_be_sent')
break
case 'not_allowed':
showToaster('errors.not_allowed')
break
default:
showToaster(error, false)
break
}
}
export const showToaster = (msg, t = true) => {
const { global } = window.i18n
const notificationStore = useNotificationStore()
notificationStore.showNotification({
type: 'error',
message: t ? global.t(msg) : msg,
})
}