ruby_open_weather_map icon indicating copy to clipboard operation
ruby_open_weather_map copied to clipboard

better error handling

Open rpbaltazar opened this issue 10 years ago • 2 comments

JSON::ParserError: 757: unexpected token at '500 /proxy/data/2.5/forecast?q=%2ccoimbra%2c+pt& ' /app/vendor/bundle/ruby/2.0.0/gems/json-1.8.2/lib/json/common.rb:155:in parse' /app/vendor/bundle/ruby/2.0.0/gems/json-1.8.2/lib/json/common.rb:155:inparse' /app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/base.rb:40:in parse_response' /app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/base.rb:17:inretrive' /app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/api.rb:7:in `city'

rpbaltazar avatar May 07 '15 01:05 rpbaltazar

Kindly provide more details about how you reached this issue. Would be great if you could share the piece of the code so that we can reproduce this error.

coderhs avatar May 07 '15 06:05 coderhs


    def forecast(location)
      location_forecast = OpenWeather::Forecast.city(location)
      if location_forecast['cod'] == '200'
        forecast_to_use = get_closest_forecast location_forecast['list']
        build_weather_string location, forecast_to_use
      else
        build_error_message location
      end
    end

Nothing special. I believe it might have to do with quotas and the openweather server answering with an error code and not parseable JSON. If you take a closer look at the error that I pasted before,

JSON::ParserError: 757: unexpected token at '500

Seams that the server is answering you with 500 (internal server error) and then you try to parse it which causes an exception.

rpbaltazar avatar May 12 '15 01:05 rpbaltazar