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

**URL:** <https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425>\
**Category:** Developers\
**Tags:** homey-pro\
**Created:** [December 30, 2023, 1:22pm UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425 "2023-12-30T13:22:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rds](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rds/32/96057_2.png) [@rds](https://community.homey.app/u/rds)\
**Post date:** [December 30, 2023, 1:22pm UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425/1 "2023-12-30T13:22:52Z")

</div>

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! 🙂

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.

```auto
<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?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 30, 2023, 2:20pm UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425/2 "2023-12-30T14:20:57Z")

</div>

Looks like a bug, created an issue [here](https://github.com/athombv/homey-apps-sdk-issues/issues/330).

---

<div class="post-metadata">

**Author:** ![rds](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rds/32/96057_2.png) [@rds](https://community.homey.app/u/rds)\
**Post date:** [December 30, 2023, 11:18pm UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425/3 "2023-12-30T23:18:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 31, 2023, 7:02am UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425/4 "2023-12-31T07:02:45Z")

</div>

Feel free to add a comment to the issue I opened, more info is more better 👍🏻

---

<div class="post-metadata">

**Author:** ![rds](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rds/32/96057_2.png) [@rds](https://community.homey.app/u/rds)\
**Post date:** [December 31, 2023, 2:49pm UTC](https://community.homey.app/t/custom-pairing-views-catch-never-catching-errors-when-calling-homey-createdevice/99425/5 "2023-12-31T14:49:03Z")

</div>

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