# JSON.parse promise error

**URL:** <https://community.homey.app/t/json-parse-promise-error/11257>\
**Category:** Developers\
**Created:** [March 31, 2019, 9:47pm UTC](https://community.homey.app/t/json-parse-promise-error/11257 "2019-03-31T21:47:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Some1](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/some1/32/8283_2.png) [@Some1](https://community.homey.app/u/Some1)\
**Post date:** [March 31, 2019, 9:47pm UTC](https://community.homey.app/t/json-parse-promise-error/11257/1 "2019-03-31T21:47:39Z")

</div>

Not sure what I do wrong here, the code I execute:

> this.ws.on(‘message’, (json) =\> {  
> let messageData = {};  
> if(json) {  
> try {  
> messageData = JSON.parse(json);  
> } catch (err) {  
> messageData = {};  
> console.log(err);  
> }  
> }

but it returns in the following error:

> ```
> (node:26596) UnhandledPromiseRejectionWarning: Error: invalid_type
> at Object.JSON.parse (/opt/homey-client/system/helpers/jsonfns.js:1:1190)
> at JSON.parse (<anonymous>)
> at jsonToObject (/opt/homey-client/system/helpers/jsonfns.js:1:1083)
> at function.e.data.map.e (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1379)
> at Array.map (<anonymous>)
> at HomeyClient._onMessage (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1372)
> at emitTwo (events.js:126:13)
> at process.emit (events.js:214:7)
> at emit (internal/child_process.js:762:12)
> at _combinedTickCallback (internal/process/next_tick.js:142:11)
> (node:26596) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
> (node:26596) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> 
> ```

I was not aware that JSON.parse was async, nor that excuting it within a try catch could cause something like this. I want to prevent my driver from exiting so how would I prevent this error?  
If for some reason I get invalid responses from my client I need to be able to handle those.

---

<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:** [April 1, 2019, 8:14am UTC](https://community.homey.app/t/json-parse-promise-error/11257/2 "2019-04-01T08:14:18Z")

</div>

The error is thrown somewhere inside Homey’s `homey-client` lib, not in your code.

---

<div class="post-metadata">

**Author:** ![Some1](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/some1/32/8283_2.png) [@Some1](https://community.homey.app/u/Some1)\
**Post date:** [April 1, 2019, 8:42am UTC](https://community.homey.app/t/json-parse-promise-error/11257/3 "2019-04-01T08:42:30Z")

</div>

So this is nothing I need to worry about?

---

<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:** [April 1, 2019, 8:44am UTC](https://community.homey.app/t/json-parse-promise-error/11257/4 "2019-04-01T08:44:21Z")

</div>

It’s still an error that you should track down (not sure what `invalid_type` means, perhaps it expects a `Number` but you pass a `String` somewhere), but it doesn’t look like it’s caused by the code you posted.
