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:
parent
b04a52676e
commit
3cf493eb4f
3 changed files with 45 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue