parse_error

parse_error()
Class Public methods

Returns the class of the error that will be raised when there is an error in decoding JSON. Using this method means you won't directly depend on the ActiveSupport's JSON implementation, in case it changes in the future.

begin
  obj = ActiveSupport::JSON.decode(some_string)
rescue ActiveSupport::JSON.parse_error
  Rails.logger.warn("Attempted to decode invalid JSON: #{some_string}")
end
doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.