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

125
Views
How can I return a new promise from the waiting request in JavaScript?

I would like to return a new promise that has the data for both the success case and the error case.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you could use this way:

 const async myfunction = (bodyData) { const totalData = await new Promise((dataSuccessReturn, errorReturn) => { axios({ method: 'POST', url: `${API}/users/user/`, // your address api url for example localHost:8000/users/user headers: { "Content-Type": "application/json" }, data: bodyData }) .then(res => { dataSuccessReturn(res.data) }) .catch(error => { errorReturn(error.response.data.message) }) }) return totalData }

This will generate a total data with a success case and an error case if there is one.

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