close

[Fixed] UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block

Today We are Going To Solve UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block in nodejs. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Error?

  1. How to Fix UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Error?

    To Fix UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Error just Avoid to use .catch(error => { throw error}). Here you have to use it as like below. Avoid to use .catch(error => { throw error}). Just use the below code to solve your error. router.get("/yourApicall", authCheck, async (req, res, next) => { try { data= yourdata res.send(data) } catch (err) { next(err); } })

  2. UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block

    To Fix UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Error just Avoid to use .catch(error => { throw error}). Here you have to use it as like below. Avoid to use .catch(error => { throw error}). Just use the below code to solve your error. router.get("/yourApicall", authCheck, async (req, res, next) => { try { data= yourdata res.send(data) } catch (err) { next(err); } })

Solution 1 : Avoid to use .catch(error => { throw error})

Here you have to use it as like below. Avoid to use .catch(error => { throw error}). Just use the below code to solve your error.

router.get("/yourApicall", authCheck, async (req, res, next) => {
  try {

    data= yourdata
    res.send(data)
  } catch (err) {
    next(err);
  }
})

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read These Solutions

Leave a Comment