Rescuing BubbleWrap::JSON::ParserError

175 views
Skip to first unread message

Neil

unread,
Mar 2, 2013, 12:40:46 PM3/2/13
to bubbl...@googlegroups.com
Hi all

If the web API is inaccessible and BW attempts to make a request, the app crashes with a BubbleWrap::JSON::ParserError. Adding a begin rescue doesn't seem to prevent the app from crashing. E.g:

begin
  BW::HTTP.post(url, payload: payload) do |response|
    if response && response.body
      data = BW::JSON.parse(response.body.to_str)
      # use data
    end
  end
rescue BubbleWrap::JSON::ParserError => exception
  return nil
end

Is there some way to catch & raise an error from BW here? Or is BW able to check if the URL will respond in the first instance (preventing the subsequent ParserError)?

Thanks in advance

Neil 

Andy Waite

unread,
Mar 2, 2013, 12:59:00 PM3/2/13
to bubbl...@googlegroups.com
I think you may perform the rescue from inside the callback, i.e.:

  BW::HTTP.post(url, payload: payload) do |response|
    if response && response.body
      begin
        data = BW::JSON.parse(response.body.to_str)
      rescue BubbleWrap::JSON::ParserError => exception
        return nil
      end
      # use data
    end
  end


Neil 

--
You received this message because you are subscribed to the Google Groups "BubbleWrap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bubblewrap+...@googlegroups.com.
To post to this group, send email to bubbl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/bubblewrap/-/npbIaZNc9_AJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Neil

unread,
Mar 2, 2013, 1:13:45 PM3/2/13
to bubbl...@googlegroups.com, an...@andywaite.com
Hi Andy. The error still isn't being caught:

(main)> 2013-03-02 18:08:02.685 App[XXXXX:c07] json.rb:21:in `parse:': Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value.) UserInfo=0x9d48f50 {NSDebugDescription=No value.} (BubbleWrap::JSON::ParserError)

Abdo Achkar

unread,
Apr 10, 2014, 7:08:18 AM4/10/14
to bubbl...@googlegroups.com, an...@andywaite.com
Hello Neil,

Have you found a way to rescue this error?
Reply all
Reply to author
Forward
0 new messages