ActiveRecord::RecordInvalid will be triggered if you use save! or create! then you can inspect b.errors
See https://api.rubyonrails.org/classes/ActiveRecord/RecordInvalid.html
Instead of raising the exception you could do something like
if a.save
redirect_to a
else
render json: {errors: a.errors}