lib/yajl/json_gem/encoding.rb in yajl-ruby-0.6.3 vs lib/yajl/json_gem/encoding.rb in yajl-ruby-0.6.4

- old
+ new

@@ -11,37 +11,40 @@ "\"#{to_s}\"" end end module JSON + class JSONError < StandardError; end unless defined?(JSON::JSONError) + class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError) + def self.generate(obj, opts={}) begin options_map = {} if opts.has_key?(:indent) options_map[:pretty] = true options_map[:indent] = opts[:indent] end Yajl::Encoder.encode(obj, options_map) - rescue Yajl::ParseError => e - raise JSON::ParserError, e.message + rescue Yajl::EncodeError => e + raise JSON::GeneratorError, e.message end end def self.pretty_generate(obj, opts={}) begin options_map = {} options_map[:pretty] = true options_map[:indent] = opts[:indent] if opts.has_key?(:indent) Yajl::Encoder.encode(obj, options_map) - rescue Yajl::ParseError => e - raise JSON::ParserError, e.message + rescue Yajl::EncodeError => e + raise JSON::GeneratorError, e.message end end def self.dump(obj, io=nil, *args) begin Yajl::Encoder.encode(obj, io) - rescue Yajl::ParseError => e - raise JSON::ParserError, e.message + rescue Yajl::EncodeError => e + raise JSON::GeneratorError, e.message end end end \ No newline at end of file