2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-21 19:11:18 +08:00

FIX: Apply contract checks when first creating a badge

This commit is contained in:
riking 2014-09-02 13:22:52 -07:00
parent b04a52676e
commit 3cf493eb4f
3 changed files with 45 additions and 29 deletions

View file

@ -11,6 +11,12 @@ module JsonError
# If it looks like an activerecord object, extract its messages
return {errors: obj.errors.full_messages } if obj.respond_to?(:errors) && obj.errors.present?
# If we're passed an array, it's an array of error messages
return {errors: obj.map {|e| e.to_s}} if obj.is_a?(Array) && obj.present?
# Log a warning (unless obj is nil)
Rails.logger.warn("create_errors_json called with unrecognized type: #{obj.inspect}") if obj
# default to a generic error
JsonError.generic_error
end