Q:

Return resolve-value from async function

In my project I use promise (code below), how it is possible, that promise still pending, when I used keyword await. Can someone help me figure out, what I'm doing wrong?

const getTs = async () => {
  const response = await axios.get('...')
    .then(res => res.data)
    .catch(() => 'ERROR');

  return response;
};

console.log(getTs()); // Promise { <pending> }

A:

The await does only stop the execution of the async function body, nothing else. The caller is not blocked, the code is still asynchronous, and you get back a promise. If you want to log the result, you have to wait for it.
const getTs = () => axios.get('...').then(res => res.data).catch(() => 'ERROR');

getTs().then(console.log);
//     ^^^^^

or
async function getTs() {
  try {
    const res = await axios.get('...');
    return res.data;
  } catch (e) {
    return 'ERROR';
  }
}

async function main() {
  const response = await getTs();
//                 ^^^^^
  console.log(response)
}
main();

