FIX: Improve error messages for invites (#12714)

The error messages used to include an unnecessary 'Validation failed:
Email' prefix which was removed.
This commit is contained in:
Dan Ungureanu
2021-04-15 14:46:32 +03:00
committed by GitHub
parent c60668a052
commit 85d4b60a45
5 changed files with 16 additions and 7 deletions

View File

@@ -104,8 +104,10 @@ class InvitesController < ApplicationController
else
render json: failed_json, status: 422
end
rescue Invite::UserExists, ActiveRecord::RecordInvalid => e
rescue Invite::UserExists => e
render_json_error(e.message)
rescue ActiveRecord::RecordInvalid => e
render_json_error(e.record.errors.full_messages.first)
end
end
@@ -175,7 +177,7 @@ class InvitesController < ApplicationController
begin
invite.update!(params.permit(:email, :custom_message, :max_redemptions_allowed, :expires_at))
rescue ActiveRecord::RecordInvalid => e
return render_json_error(e.message)
return render_json_error(e.record.errors.full_messages.first)
end
end