Question:
NodeJS Error Solved: Handling Not Sending Error To Frontend

If you want the NodeJS Error to propagate which it sounds like you do, then you need to rethrow the error after logging it.


Your .catch() handler in deletePayment() is "eating" or "handling" the error and thus the error does not propagate back to the caller. It logs it but does nothing else thus changing the rejection into a resolved promise. The caller thinks the operation succeeded.


async function deletePayment(paymentId) {


  const options = await ApiOptionsService.deleteItem(paymentId)


  const response = await got(options).catch(err=>{

    console.log('error ' +err.message); 

    // re-throw the error so the caller will get it

    throw err;

  });

  return response.body;

}


But, this code is only logging some errors and is mixing await with .catch() which is generally not favored. If you want to log any errors in this function, I'd do it like this:


async function deletePayment(paymentId) {

    try {

        const options = await ApiOptionsService.deleteItem(paymentId)

        const response = await got(options);

        return response.body;

    } catch(err) {

        // log error

        console.log('error ' + err.message);

        // rethrow so caller gets rejection

        throw err;

    }

}


Answered by:> jfriend00

Credit:> StackOverflow


Blog Links: 

>How do I customize controller actions in Laravel Jetstream?

>Run Laravel Project to Active Local Server

>How to show encrypted user id in URL in Laravel?

>How to fix Laravel LiveWire listener?


Nisha Patel

Nisha Patel

Submit
0 Answers