mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:01:22 +08:00
FIX: editing a post wasn't showing error messages from the server
This commit is contained in:
@ -9,18 +9,17 @@ module JsonError
|
||||
private
|
||||
|
||||
def create_errors_array(obj)
|
||||
|
||||
# If we're passed a string, assume that is the error message
|
||||
return {errors: [obj]} if obj.is_a?(String)
|
||||
return { errors: [obj] } if obj.is_a?(String)
|
||||
|
||||
# If it's an AR exception target the record
|
||||
obj = obj.record if obj.is_a?(ActiveRecord::RecordInvalid)
|
||||
|
||||
# If it looks like an activerecord object, extract its messages
|
||||
return {errors: obj.errors.full_messages } if obj.respond_to?(:errors) && obj.errors.present?
|
||||
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?
|
||||
return { errors: obj.map(&: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
|
||||
@ -30,7 +29,7 @@ module JsonError
|
||||
end
|
||||
|
||||
def self.generic_error
|
||||
{errors: [I18n.t('js.generic_error')]}
|
||||
{ errors: [I18n.t('js.generic_error')] }
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user