mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FEATURE: improve API error reporting for invalid records
This commit is contained in:
@ -129,6 +129,14 @@ class ApplicationController < ActionController::Base
|
||||
)
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::RecordInvalid do |e|
|
||||
if request.format && request.format.json?
|
||||
render_json_error e, type: :record_invalid, status: 422
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
# If they hit the rate limiter
|
||||
rescue_from RateLimiter::LimitExceeded do |e|
|
||||
render_rate_limit_error(e)
|
||||
|
Reference in New Issue
Block a user