I'm sending a request to a backend THAT IS OFFLINE using axios
const backendClient = axios.create({
baseURL : env
});
The API gets called
export const createExpensesRecord = async (createExpenseRecordCmd) => {
try {
await backendClient.post("/api/accounting/expenses", createExpenseRecordCmd)
return true
} catch(error) {
return false
}
}
The error code should trigger, as the backend is not reachable with Error: Network Error
.
function submitAccountingRecord() {
if(formDataValid()) {
if(createExpensesRecord(cmd)) {
console.log("SUCCESS")
} else {
console.log("FAILED")
}
...
}
}
No matter what I do, I always receive SUCCESS. Played around with it for over an hour and couldn't get consistant behaviour. What am I doing wrong?
Be aware that I tried multiple approaches, maybe we can stick to this one than suggestion different options to solve it. It's the most straight forward approach I could think of
---- UPDATE
await function submitAccountingRecord() {
if(formDataValid()) {
if(await createExpensesRecord(cmd)) {
console.log("SUCCESS")
} else {
console.log("FAILED")
}
...
}
}