fine tuned error handling.

working on #25
This commit is contained in:
Sockenklaus
2021-11-28 09:02:27 +01:00
parent 6ba4b38552
commit a0a03ea9ee
2 changed files with 21 additions and 18 deletions

View File

@@ -5,8 +5,6 @@
@save="submitForm"
@toggleEdit="toggleEdit"
/>
{{employeeStore.employee }}
<form class="text-start" @keyup.enter="submitForm">
<div class="row mb-5">
<div class="col pe-5">
@@ -180,8 +178,6 @@ import { useUser } from '@/stores/user'
import { useEmployee } from '@/stores/employee'
import EmployeeFormControls from '@/components/Employees/EmployeeFormControls.vue'
import { IMaskComponent as MaskInput } from 'vue-imask'
import employees from '@/stores/employees'
/**
* Props
@@ -247,7 +243,7 @@ const editEmployee = ref(props.id ? false : true)
}
}))
const v$ = useVuelidate(rules, employee)
const v$ = useVuelidate(rules, employee) // error because wrong return type in validateApiErrors()...
/**
@@ -279,13 +275,14 @@ function toggleEdit() {
}
async function submitForm(){
if(await v$.value.$validate()) {
if(await v$.value.$validate()){
if(employee.value.id){
await employeeStore.patchEmployee()
toggleEdit()
if(await employeeStore.patchEmployee()){
toggleEdit()
}
}
else if(await employeeStore.postEmployee()){
else if(await employeeStore.postEmployee()) {
router.push({name: "Employees/Index"})
}
}

View File

@@ -3,7 +3,6 @@ import axios from '@/axios'
import { useUser } from './user'
import { useNotifications } from './notifications'
import Axios from 'axios'
import { stubFalse } from 'lodash'
const user = useUser()
const notifications = useNotifications()
@@ -117,13 +116,19 @@ export const useEmployee = defineStore({
Object.assign(this.clean.employee, this.employee)
notifications.add('success', result.statusText)
return true
}
catch(error) {
if(error instanceof Error) {
console.log(error)
console.log("Patch Employee Error")
if(Axios.isAxiosError(error)) {
let data = error.response?.data as { errors: EmployeeApiValidationError[] }
this.apiValidationErrors = [...data.errors]
}
else if(error instanceof Error) {
notifications.add('danger', error.message, -1)
}
else console.log(error)
console.log(error)
return false
}
},
@@ -142,17 +147,18 @@ export const useEmployee = defineStore({
this.assignTruthyValues(this.clean.employee, result.data)
notifications.add('success', result.statusText)
console.log(result)
return true
}
catch(error){
console.log("enter catch")
console.log("Post Employee Error")
if(Axios.isAxiosError(error)) {
console.log("enter axios error")
let data = error.response?.data as { errors: EmployeeApiValidationError[] }
console.log(data)
this.apiValidationErrors = [...data.errors]
}
else if(error instanceof Error) {
notifications.add('danger', error.message, -1)
}
console.log(error)
return false
}
},