diff --git a/app/api/defaults.rb b/app/api/defaults.rb index 7772e6c4..730841f1 100644 --- a/app/api/defaults.rb +++ b/app/api/defaults.rb @@ -15,7 +15,9 @@ module Defaults # Global handler for simple not found case rescue_from ActiveRecord::RecordNotFound do |e| log_backtrace(e) - error!({ errors: Array(e.message) }, 404) + + model = e.respond_to?(:model) && e.model ? e.model : 'Record' + error!({ errors: ["#{model} not found"] }, 404) end # Global handler for validation errors diff --git a/app/api/v1/resources.rb b/app/api/v1/resources.rb index 7c23dff8..364a4033 100644 --- a/app/api/v1/resources.rb +++ b/app/api/v1/resources.rb @@ -88,7 +88,7 @@ class Resources < MountableAPI @envelope.inner_resource_from_graph(params[:id]) )) rescue ActiveRecord::RecordNotFound - raise ActiveRecord::RecordNotFound, "Couldn't find Resource" + raise ActiveRecord::RecordNotFound.new(nil, 'Resource') end end end diff --git a/spec/api/v1/base_spec.rb b/spec/api/v1/base_spec.rb index c0773b04..8d736047 100644 --- a/spec/api/v1/base_spec.rb +++ b/spec/api/v1/base_spec.rb @@ -15,7 +15,7 @@ let(:test_response) { raise ActiveRecord::RecordNotFound } it { expect_status(404) } - it { expect_json('errors.0', 'ActiveRecord::RecordNotFound') } + it { expect_json('errors.0', 'Record not found') } end context 'Grape::Exceptions::Validation' do # rubocop:todo RSpec/ContextWording diff --git a/spec/api/v1/publish_spec.rb b/spec/api/v1/publish_spec.rb index 6d0e7472..8d226920 100644 --- a/spec/api/v1/publish_spec.rb +++ b/spec/api/v1/publish_spec.rb @@ -706,10 +706,7 @@ it 'returns 404' do transfer_ownership expect_status(:not_found) - expect_json( - 'errors.0', - "Couldn't find Organization with 'id'=#{new_organization_id}" - ) + expect_json('errors.0', 'Organization not found') end end @@ -820,10 +817,7 @@ it 'returns 404' do transfer_ownership expect_status(:not_found) - expect_json( - 'errors.0', - "Couldn't find Organization with 'id'=#{new_organization_id}" - ) + expect_json('errors.0', 'Organization not found') end end diff --git a/spec/api/v1/resources_spec.rb b/spec/api/v1/resources_spec.rb index 49886df0..99b09530 100644 --- a/spec/api/v1/resources_spec.rb +++ b/spec/api/v1/resources_spec.rb @@ -48,7 +48,7 @@ it 'cannot retrieve the desired resource' do expect_status(:not_found) - expect_json(errors: ["Couldn't find Resource"]) + expect_json(errors: ['Resource not found']) end end # rubocop:enable RSpec/MultipleMemoizedHelpers