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

193
Views
how to get axios error post/request payload on catch

when I catch an axios error, how can i get the request body? (what I've sent to the server, not the server response)

example of what i want to achieve

axios.post("url",{
    name:jesus
}).then((response) => {
    ....
}).catch((error) => {
    console.log(error.request.body)  //name:jesus
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can access the original request data via error.config.data. Note that it will be the serialised format (in your case JSON) so you may need to parse it back into a JS object.

axios
  .post("http://httpbin.org/status/400", {
    name: "jesus",
  })
  .then((res) => {
    console.log("response", res);
  })
  .catch((error) => {
    const data = JSON.parse(error.config.data);
    console.error("request data", data);
  });
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

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!