FIX: include error message if the "accept invite" process fails

FIX: include error message if the “accept invite” process fails

diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index a178e401..884f67e 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -63,7 +63,8 @@ class InvitesController < ApplicationController
       rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
         render json: {
           success: false,
-          errors: e.record&.errors&.to_hash || {}
+          errors: e.record&.errors&.to_hash || {},
+          message: I18n.t('invite.error_message')
         }
       end
     else
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 286a8f2..c525fe1 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -208,6 +208,7 @@ en:
       <p>If you remember your password you can <a href="%{base_url}/login">Login</a>.</p>
 
       <p>Otherwise please <a href="%{base_url}/password-reset">Reset Password</a>.</p>
+    error_message: "There was an error accepting invite. Please contact the site's administrator."
     user_exists: "There's no need to invite <b>%{email}</b>, they <a href='%{base_path}/u/%{username}/summary'>already have an account!</a>"
     confirm_email: "<p>You’re almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.</p><p>If it doesn’t arrive, check your spam folder.</p>"
 
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index 037d2aa..b2b7f41 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -213,6 +213,18 @@ describe InvitesController do
       end
     end
 
+    context 'with an invalid invite record' do
+      let(:invite) { Fabricate(:invite, email: "John Doe <john.doe@example.com>") }
+      it "responds with error message" do
+        put "/invites/show/#{invite.invite_key}.json"
+        expect(response.status).to eq(200)
+        json = JSON.parse(response.body)
+        expect(json["success"]).to eq(false)
+        expect(json["message"]).to eq(I18n.t('invite.error_message'))
+        expect(session[:current_user_id]).to be_blank
+      end
+    end
+
     context 'with a deleted invite' do
       let(:topic) { Fabricate(:topic) }

GitHub sha: 38179324