# Homey Script - how to create AbortController() for fetch

**URL:** <https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027>\
**Category:** Developers\
**Created:** [July 22, 2023, 6:59am UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027 "2023-07-22T06:59:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_R](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tim_r/32/82292_2.png) [@Tim\_R](https://community.homey.app/u/Tim_R)\
**Post date:** [July 22, 2023, 6:59am UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027/1 "2023-07-22T06:59:53Z")

</div>

Hey all,

I’m trying to make a simple script for Homey to check if it still has wifi connection. I do this by checking if it can reach the router. For this I use [Fetch](https://athombv.github.io/com.athom.homeyscript/global#.fetch).

Now I want to cut back on the default timeout time and implement an error handler. (If not reachable) But I seem to be unable to create an instance of `AbortController()` [as per the docs.](https://github.com/node-fetch/node-fetch/blob/main/README.md#request-cancellation-with-abortsignal). Is there way to achieve this? Is there a better way? Or is this not implemented in HS?

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 22, 2023, 10:52am UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027/2 "2023-07-22T10:52:15Z")

</div>

Looks like the same post as [Bug? - Homey Script card keeps running](https://community.homey.app/t/bug-homey-script-card-keeps-running/85024)

---

<div class="post-metadata">

**Author:** ![Tim\_R](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tim_r/32/82292_2.png) [@Tim\_R](https://community.homey.app/u/Tim_R)\
**Post date:** [July 22, 2023, 1:09pm UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027/3 "2023-07-22T13:09:41Z")

</div>

Hm no 🙂  
The other post is about a bug in the Homey Script editor.  
This is a post about `how to set a custom timeout on fetch`. The Homey docs say fetch is a shortcut to [node-fetch](https://www.npmjs.com/package/node-fetch/v/2.6.7).

And node-fetch says you can set/handle a fetch timeout with `AbortController()`. But as the docs state, you have to import it. But since your cannot import anything in HS I’m looking for a way to add `AbortController()` OR find an alternative to setting a custom timeout. Default is 120 sec I believe.

---

<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:** [July 22, 2023, 1:11pm UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027/4 "2023-07-22T13:11:26Z")

</div>

> [@Tim\_R](#):
>
> Is there a better way?

> **[Net Scan](https://homey.app/en-us/app/com.netscan/Net-Scan/)**
>
> Watch devices on your local network by scanning for TCP ports

---

<div class="post-metadata">

**Author:** ![Tim\_R](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tim_r/32/82292_2.png) [@Tim\_R](https://community.homey.app/u/Tim_R)\
**Post date:** [July 22, 2023, 1:35pm UTC](https://community.homey.app/t/homey-script-how-to-create-abortcontroller-for-fetch/85027/5 "2023-07-22T13:35:02Z")

</div>

Thanks Robert.

I’ve tried to do it with HS, because in my head it would be a quick solution. Guess I have to learn to stop comparing Homey Script to Javascript, since it’s a very closed ecosystem.

Yes, your app suggestion did the trick.

 ![Screenshot 2023-07-22 at 15.29.23](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/4/245a32211cc4c519df0995a95315aebfde025cd0.jpeg)

I’ll add a global var for a counter to stop rebooting after 3 times to prevent an infinite loop if something else is happening. Like for the router to run an update or whatever.
