Custom pairing views: catch never catching errors when calling Homey.createDevice

This is probably me doing something completely wrong I am not an experienced JavaScript developer. I’m stuck here now and reaching out to the community to help me unstuck! :slight_smile:

I have a custom view for pairing a new device. In this view, user can enter a House Code and a Unit Code and a Name for the unit. Regardless of outcome from Homey.createDevice() the then() is always called and the catch() is never called.

I’m letting Homey API fail the call if I register two devices with the same data.id, this will yield a 409 conflict error. Am hoping to pick that error code up and display a nice message to the user and let him try again.

<script type="text/javascript">
  (function () {
    const $create = document.getElementById("receiver-add-create");
    let creatingDevice = false;

    $create.addEventListener("click", (e) => {
      if (creatingDevice) return;
      creatingDevice = true;
      
       ... 

      Homey.createDevice(device)
        .then(function () {
          return Homey.done();
        })
        .catch(function (err) {
          creatingDevice = false;
          return Homey.Alert(
            "There is already a device with that House Code and Unit Code combination."
          );
        });
    });
  })();
</script>

EXPECTED: Display an alert if any error happens and if Home.createDevice() is successful paring window will be closed.

ACTUAL: Regardless of outcome from Homey.createDevice then() is called, catch() is never called on errors, and if an error occurs Homey will display an error toast I cannot get rid of.

QUESTION: Am I going about this in the wrong way? If so, what should I be doing instead?

Looks like a bug, created an issue here.

I tried this in the Iphone Homey App, and I got a little different outcome.

When not failing, the then()call is made, but catch() is not called when it fails.

So it seems like in Edge or Chome in the Web App, catch() is never called, then() is always called.
In the IPhone App, catch() is never called, then() is only called on success.

Feel free to add a comment to the issue I opened, more info is more better :+1:t2:

Thanks for your help, I’ve added a comment to the Issue now. :slight_smile: