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

86
Views
Handling Promise object from function

I just started working with Promise objects in JS and I can't figure out something.

I need to create a function that receives a Promise object as parameter, if the promise is resolved I need to return a success object, otherwise an empty Error object. But it seems to not be returning anything.

export default function handleResponseFromAPI(promise) {
    promise.then(() => {
        console.log('Got a response from the API');
        return { status: 200, body: 'Success' };
    }, () => {
        console.log('Got a response from the API');
        return new Error();
    });
}

And I call it here:

import handleResponseFromAPI from "./2-then";

const promise = Promise.resolve();
const returnObject = handleResponseFromAPI(promise);
console.log(returnObject);

What shows up on console:

undefined
Got a response from the API

I can see that first it returns undefined and then prints the message from my function. Anyone cares to explain the process of this?

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