FEATURE: improve API error reporting for invalid records

This commit is contained in:
Sam
2018-08-21 11:54:34 +10:00
parent f939bdbf44
commit 2d96160192
2 changed files with 14 additions and 0 deletions

View File

@ -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)