How to throw errors in a try/catch block inside the async function?

There is such code:

async function () {
try {
const response = await doAsyncOperation();
if (response.isError) {
throw new Error(response.isError)
return 'All good'
 } catch (err) {
return 'Error happened'

Here I'm trying to check whether response error, and if so, throw an error (thereby it should fall into the catch), and in obrabotal catch her, however, this code causes the error:
at process._tickCallback (internal/process/next_tick.js:68:7)

and before the line return 'Error happened' to not get it.
What am I doing wrong? And how?
April 19th 20 at 12:09
0 answer

Find more questions by tags Asynchronous programmingJavaScript