Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

VD & incorrect json response


Question

Posted (edited)

hi

 

I have VD with periodic polling internet resource

sometimes response from a resource invalid. my VD throw an exception in json.decode and stopped

so, my question is - how to catch exceptions from http and prevent to stop VD main loop?

 

notice: response, status, errorCode - all OK and status - 200

Edited by 10der

5 answers to this question

Recommended Posts

  • 0
Posted

Can you print returned data? What is the returned data size of it when ok and when not ok?

 

/Peo

  • 0
Posted

Hi @10der,

 

One of the ways is to parse received data and check if there is structure missing. Since you didn't provide any structure here is what I use to check data returned from Netatmo weather station:

Please login or register to see this code.

Above function is called from code after getting response:

Please login or register to see this code.

Of course this code is from scene, but it should also work in VD.

 

if there is only one part that is missing from table sometimes, like for example rain participation from weather forecast then you can check by comparing with nil:

Please login or register to see this code.

I thank to @petergebruers for above solutions that he kindly shared!

 

  • 0
  • Inquirer
  • Posted

    @Sankotronic you are a monster! :) thank you so much.

    a crazzzy solution as for me :)
     

    • 0
    Posted

    I hope that it will help.

     

    There is one more solution if nothing else helps. I had also problems with WU weather rain participation data. It is not nil neither empty string or anything recognizable by normal comparison. I haven't try to use conversion from code to char, but at the end this helped, at least i think it helped since code didn't stop since:

    Please login or register to see this code.

    This one I still need to analyze when it happens again except if @petergebruers or someone else has answer to it.

     

     

    • 0
    Posted

    Hi @10der,

     

    Here is one more way how to check in VD if you get in response json table or some scrambled and unwanted data that json.decode can't process and stops with error:

    Please login or register to see this code.

    Using pcall (protected call) function prevents debugger from stopping code and returns false result and message if there is error. In above case if response does not contain table data.

     

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...