mirror of
https://github.com/discourse/discourse.git
synced 2025-08-21 19:11:18 +08:00
Adds better reusable error message support. Added to fetching remote
posts. /cc @riking
This commit is contained in:
parent
b250aa36a0
commit
558a06a117
6 changed files with 87 additions and 5 deletions
21
lib/json_error.rb
Normal file
21
lib/json_error.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module JsonError
|
||||
|
||||
def create_errors_json(obj)
|
||||
|
||||
# If we're passed a string, assume that is the error message
|
||||
return {errors: [obj]} if obj.is_a?(String)
|
||||
|
||||
# If it looks like an activerecord object, extract its messages
|
||||
return {errors: obj.errors.full_messages } if obj.respond_to?(:errors) && obj.errors.present?
|
||||
|
||||
# default to a generic error
|
||||
JsonError.generic_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.generic_error
|
||||
{errors: [I18n.t('js.generic_error')]}
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue