Merge pull request #2741 from riking/badges_create_checks

FIX: Apply contract checks when first creating a badge
This commit is contained in:
Sam
2014-09-03 22:19:09 +10:00
6 changed files with 55 additions and 38 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