./lib/joshua/response.rb in joshua-0.2.4 vs ./lib/joshua/response.rb in joshua-0.2.7

- old
+ new

@@ -37,10 +37,12 @@ if force @message = value else @message ||= value end + + nil end # api meta response, any data is allowed def meta key, value = nil if value @@ -49,22 +51,29 @@ @meta[key] end end # add api response error - def error text, args={} + def error messages, args={} code = args.delete(:code) status = args.delete(:status) raise 'Key %s is not supported' % args.keys.first if args.keys.first @status ||= status if status - text = text.to_s - @errors[:code] ||= code if code @errors[:messages] ||= [] - @errors[:messages].push text unless @errors[:messages].include?(text) + + unless messages.class == Array + messages = [messages.to_s] + end + + for text in messages + if text.present? && text[0, 2] != '["' && !@errors[:messages].include?(text) + @errors[:messages].push text + end + end end def error? !!(@errors[:messages] || @errors[:details]) end