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

269
Views
Axios does not send appropriate error response [React]

I'm trying to handle the error responses from Axios with React, but when i try to console log it the error is Network error and the error.response is undefined.

The request is a simple POST with the Authorization header correctly setted, when I try to do the same request on Postman it works correctly and I'am able to see the error response.

The request is made after the user fills a form and click on a button.

async function create() {
  const response = await Axios.post(
    "/api/disposal-requests/", // the base url is setted when the application mounts `Axios.defaults.baseURL = process.env.REACT_APP_API_URL`
    {
      description: "Description",
      url: "Url",
      key: "Key",
      location_geoname_id: "City",
    }
  );

  return response.data;
}

When a user clicks on a button there is another function that calls the create.

async function onClick() {
  try {
    await create();
    // Everything works fine when there are no errors
  } catch(error) {
    // Here error.response is undefined
  }
}

This is what i receive in the console.log, in the Network tab I can see the error status is 400 but even there there is no error response, I'am able to see the error response only on Postman.

enter image description here

Does anyone know what's wrong here ?

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

0

Please write await before creat(). so that if any any error occurs, catch with get that

async function onClick() {
    try {
      await create();
      // Everything works fine when there are no errors
    } catch (error) {
      // Here the error response is undefined
    }
  }
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!