# Node-red stops when i quit Kodi

**URL:** <https://discourse.nodered.org/t/node-red-stops-when-i-quit-kodi/18706>\
**Category:** General\
**Created:** [2 December 2019 18:45 UTC](https://discourse.nodered.org/t/node-red-stops-when-i-quit-kodi/18706 "2019-12-02T18:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pipo1nsano](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Pipo1nsano](https://discourse.nodered.org/u/Pipo1nsano)\
**Post date:** [2 December 2019 18:45 UTC](https://discourse.nodered.org/t/node-red-stops-when-i-quit-kodi/18706/1 "2019-12-02T18:45:11Z")

</div>

I use " node-red-contrib-kodi" to control my light when watching movies but when i quit kodi node-red crashes.. I cannot understand why..

Does anyone have a clue?

```auto
2 Dec 19:38:06 - [red] Uncaught Exception:
2 Dec 19:38:06 - SyntaxError: Failed to handle response: Unexpected token ? in JSON at position 0
    at JSON.parse (<anonymous>)
    at Schema.handleResponse (C:\Users\NAS\.node-red\node_modules\jrpc-schema\lib\Schema.js:80:21)
    at WebSocket.<anonymous> (C:\Users\NAS\.node-red\node_modules\kodi-ws\lib\Connection.js:30:18)
    at WebSocket.emit (events.js:203:13)
    at Receiver.ontext (C:\Users\NAS\.node-red\node_modules\ws\lib\WebSocket.js:841:10)
    at C:\Users\NAS\.node-red\node_modules\ws\lib\Receiver.js:536:18
    at Receiver.applyExtensions (C:\Users\NAS\.node-red\node_modules\ws\lib\Receiver.js:371:5)
    at C:\Users\NAS\.node-red\node_modules\ws\lib\Receiver.js:508:14
    at Receiver.flush (C:\Users\NAS\.node-red\node_modules\ws\lib\Receiver.js:347:3)
    at Receiver.finish (C:\Users\NAS\.node-red\node_modules\ws\lib\Receiver.js:541:12)

```

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [2 December 2019 20:02 UTC](https://discourse.nodered.org/t/node-red-stops-when-i-quit-kodi/18706/2 "2019-12-02T20:02:39Z")

</div>

File an issue on the kodi node you use. It handles disconnects improperly. Specifically, it tries to connect to Kodi which is not on, then parses the response as JSON without checking first if the response is okay. Since the response won’t be in JSON format, especially not in the expected format, the code crashes, and takes node-res down with it.

---

<div class="post-metadata">

**Author:** ![Pipo1nsano](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Pipo1nsano](https://discourse.nodered.org/u/Pipo1nsano)\
**Post date:** [4 December 2019 20:46 UTC](https://discourse.nodered.org/t/node-red-stops-when-i-quit-kodi/18706/3 "2019-12-04T20:46:00Z")

</div>

Thanks for the reply.

The issue is already submitted.. Since June 2018 😑.

> <https://github.com/PaulAvery/kodi-ws/issues/17>
>
> When running:
> kodi(host, 9090)
> .then(connection =\> {
> connection.System.Shutdown()
> console.log("Kodi Power Off Success")
> })
> Kodi Power Success
> events.js:165
> throw er; // Unhandled 'error' event
> ^
> SyntaxError:...

I will look for another way to control my lights..
