diff --git a/app/models/alma/user.rb b/app/models/alma/user.rb index d5e29604..3321f9f4 100644 --- a/app/models/alma/user.rb +++ b/app/models/alma/user.rb @@ -43,7 +43,7 @@ def find_if_active(id) return nil unless rec && rec.active? end rescue Error::AlmaRecordNotFoundError => e - return if e.message.include?('Alma query failed with response: 404') + return if %w[400 404].include? e.message raise end diff --git a/app/services/alma_services.rb b/app/services/alma_services.rb index 422b51a5..b283b664 100644 --- a/app/services/alma_services.rb +++ b/app/services/alma_services.rb @@ -50,7 +50,7 @@ def authenticate_alma_patron?(alma_user_id, alma_password) def get_user(alma_user_id) params = { view: 'full', expand: 'fees' } connection.get(user_uri_for(alma_user_id), params).tap do |res| - raise Error::AlmaRecordNotFoundError, "Alma query failed with response: #{res.status}" unless res.status == 200 + raise Error::AlmaRecordNotFoundError, res.status unless res.status == 200 end end @@ -97,7 +97,7 @@ def credit(alma_user_id, pp_ref_number, fee) payment_uri = URIs.append(fee_uri_for(alma_user_id, fee.id), '?', URI.encode_www_form(params)) connection.post(payment_uri).tap do |res| - raise Error::AlmaRecordNotFoundError, "Alma query failed with response: #{res.status}" unless res.status == 200 + raise Error::AlmaRecordNotFoundError, res.status unless res.status == 200 end end end diff --git a/spec/forms_helper.rb b/spec/forms_helper.rb index a707d89c..e78fe8cc 100644 --- a/spec/forms_helper.rb +++ b/spec/forms_helper.rb @@ -64,8 +64,18 @@ def show_path(id) it 'forbids users when active patron lookup returns Alma 404' do patron_id = Alma::Type.sample_id_for(allowed_patron_types.first) allow(AlmaServices::Patron).to receive(:get_user).with(patron_id) - .and_raise(Error::AlmaRecordNotFoundError, - 'Alma query failed with response: 404') + .and_raise(Error::AlmaRecordNotFoundError, '404') + + with_patron_login(patron_id) do + get new_form_path + expect(response).to have_http_status(:forbidden) + end + end + + it 'forbids users when active patron lookup returns Alma 400' do + patron_id = Alma::Type.sample_id_for(allowed_patron_types.first) + allow(AlmaServices::Patron).to receive(:get_user).with(patron_id) + .and_raise(Error::AlmaRecordNotFoundError, '400') with_patron_login(patron_id) do get new_form_path diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e3144568..9e8743e5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -248,7 +248,7 @@ user = User.new(uid: 'fake_uid') allow(Alma::User).to receive(:find_if_active).with('fake_uid') .and_raise(Error::AlmaRecordNotFoundError, - 'Alma query failed with response: 500') + '500') expect { user.primary_patron_record }.to raise_error(Error::AlmaRecordNotFoundError) end