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

315
Views
Accessing the HTTP error body data in an axios catch clause

I want to use HTTP errors when my API reports an error that the client should handle nicely. In my 400 API response, I set the body to the error metadata, but all my axios catch statement returns is a generic 400 error string, not the response object where I could inspect and handle the error.

example

  function (ent) {
        return axios
          .post(config.ROOT_API + '/api/backstory/', {new_parent_entity: ent, child_entity: this.entity})
          .then(({data}) => {
            console.log(data)
          })
          .catch((e) => {
            console.log(e) // this returns
          })

e is returned as as stack trace:

BackstoryUpdate.vue?8720:191 Error: Request failed with status code 400
    at createError (createError.js?2d83:16)
    at settle (settle.js?467f:17)
    at XMLHttpRequest.handleLoad (xhr.js?b50d:62) 

Whereas as the 400 response contained this body I want to access, e.g.,:

{error: "Circular reference detected", container: {id: 39, text: "abdef"}}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to access the response object within error.

function (ent) {
    return axios
      .post(config.ROOT_API + '/api/backstory/', {new_parent_entity: ent, child_entity: this.entity})
      .then(({data}) => {
        console.log(data)
      })
      .catch((e) => {
        console.log(e.response) // this returns
      })
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!