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

145
Views
Why use a promise to wrap axios API calls?

I have been using axios to make API calls using the following pattern:

axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });

In a codebase I am working on, the pattern for API calls looks like this:

export async function getUser(...) { 
   return new Promise((resolve, reject) => {
      customAxios.get("...", { params })
      .then(response => ....).then(resolve).catch(reject))
      .catch(error => 
         return new reject(...));
  });
}

Where customAxios looks like:

const customAxios = axios.create({...});
customAxios.interceptors.response.use(.....);

I haven't used Promises before, but what is the point of wrapping the axios call in a promise as oppose to style the axios documention has?

about 4 years ago · Santiago Trujillo
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!