I'm attempting to communicate with a backend server that is currently offline using axios
const backendClient = axios.create({
baseURL : env
});
The API call is made here:
export const createExpensesRecord = async (createExpenseRecordCmd) => {
try {
await backendClient.post("/api/accounting/expenses", createExpenseRecordCmd)
return true
} catch(error) {
return false
}
}
An error is expected as the backend cannot be reached, resulting in the Error: Network Error
.
function submitAccountingRecord() {
if(formDataValid()) {
if(createExpensesRecord(cmd)) {
console.log("SUCCESS")
} else {
console.log("FAILED")
}
...
}
}
Despite multiple attempts, only "SUCCESS" is logged. I've spent considerable time troubleshooting but haven't been able to resolve the issue. What am I missing?
I have explored various approaches and techniques, but would prefer to focus on this specific method before considering alternative solutions.
---- UPDATE
await function submitAccountingRecord() {
if(formDataValid()) {
if(await createExpensesRecord(cmd)) {
console.log("SUCCESS")
} else {
console.log("FAILED")
}
...
}
}