Unable to print error message from function call

I am not a JavaScript guy (can only write simple JS function), I am trying to debug a code with the JS where my backed system is passing the correct values but I am getting an error while processing the code on the UI. Here is the JS code

this.session.onvalidatemerchant = function (event) {
    this.performAuthorizeMerchantRequest(event.validationURL)
        .then(function (merchantSession) {
            this.session.completeMerchantValidation(merchantSession);
            alert("jdshhdjhjdhh");
        }.bind(this))
        .catch(this.showPaymentError.bind(this));
}.bind(this);

Here is the error handling function

showPaymentError: function () {
  //showing a message on the UI
}

I have already verified the data being passed from my backed service is correct, I don’t see the following alter alert("jdshhdjhjdhh");. There seems to be issue with the completeMerchantValidation method but I am not sure what is the root cause for failure.I tried to change my error message with something like this

showPaymentError: function (e) {
    console.log("*****111"+e)
}

but getitng the following output in the console *****111TypeError: Type error. Is there a way I can print the error from the completeMerchantValidation. Even tried to add try and catch around that method call but getting js compilation error

2 thoughts on “Unable to print error message from function call”

  1. Try this. the try catch will handle the potential error which come from performAuthorizeMerchantRequest or completeMerchantValidation.

    this.session.onvalidatemerchant = async ({ validationURL }) => {
      try {
        const merchantSession = await this.performAuthorizeMerchantRequest(validationURL)
        this.session.completeMerchantValidation(merchantSession)
        alert('jdshhdjhjdhh')
      } catch (error) {
        console.error('Oh oh, an error happened', error)
        this.showPaymentError(error);
      }
    }
    Reply

Leave a Comment