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" @save="submitForm"
@toggleEdit="toggleEdit" @toggleEdit="toggleEdit"
/> />
{{employeeStore.employee }}
<form class="text-start" @keyup.enter="submitForm"> <form class="text-start" @keyup.enter="submitForm">
<div class="row mb-5"> <div class="row mb-5">
<div class="col pe-5"> <div class="col pe-5">
@@ -180,8 +178,6 @@ import { useUser } from '@/stores/user'
import { useEmployee } from '@/stores/employee' import { useEmployee } from '@/stores/employee'
import EmployeeFormControls from '@/components/Employees/EmployeeFormControls.vue' import EmployeeFormControls from '@/components/Employees/EmployeeFormControls.vue'
import { IMaskComponent as MaskInput } from 'vue-imask' import { IMaskComponent as MaskInput } from 'vue-imask'
import employees from '@/stores/employees'
/** /**
* Props * 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,12 +275,13 @@ function toggleEdit() {
} }
async function submitForm(){ async function submitForm(){
if(await v$.value.$validate()){ if(await v$.value.$validate()){
if(employee.value.id){ if(employee.value.id){
await employeeStore.patchEmployee() if(await employeeStore.patchEmployee()){
toggleEdit() toggleEdit()
} }
}
else if(await employeeStore.postEmployee()) { else if(await employeeStore.postEmployee()) {
router.push({name: "Employees/Index"}) router.push({name: "Employees/Index"})
} }

View File

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