mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #2741 from riking/badges_create_checks
FIX: Apply contract checks when first creating a badge
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user