Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
NETWORK ERROR does not get resolved by axios

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")
            }

            ...
        }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Server being offline is not an error really. In fact, you shouldn't rely on any HTTP tool (be it axios or native fetch API). Read this thread to learn more.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!