Generalized 404 error message

pull/2555/head
Alexander Bach 10 years ago
parent c3fe4e5503
commit 409073f7e3
  1. 2
      config/locales/en.yml
  2. 2
      lib/api/errors/not_found.rb
  3. 2
      lib/api/root.rb
  4. 5
      lib/api/v3/categories/categories_api.rb
  5. 5
      lib/api/v3/projects/projects_api.rb
  6. 7
      lib/api/v3/work_packages/work_package_contract.rb
  7. 5
      lib/api/v3/work_packages/work_packages_api.rb
  8. 16
      spec/requests/api/v3/support/response_examples.rb
  9. 10
      spec/requests/api/v3/work_package_resource_spec.rb
  10. 5
      spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb

@ -1656,7 +1656,7 @@ en:
errors:
code_401: "You need to be authenticated to access this resource."
code_403: "You are not authorized to access this resource."
code_404: "Couldn\'t find %{type} with id=%{id}"
code_404: "The requested resource could not be found."
code_409: "Couldn\'t update the resource because of conflicting modifications."
invalid_content_type: "Expected CONTENT-TYPE to be '%{content_type}' but got '%{actual}'."
invalid_resource:

@ -31,7 +31,7 @@ module API
module Errors
class NotFound < ErrorBase
def initialize(message)
super 404, message + '.'
super 404, message
end
end
end

@ -120,7 +120,7 @@ module API
end
rescue_from ActiveRecord::RecordNotFound do |e|
api_error = ::API::Errors::NotFound.new(e.message)
api_error = ::API::Errors::NotFound.new(I18n.t('api_v3.errors.code_404'))
representer = ::API::V3::Errors::ErrorRepresenter.new(api_error)
error_response(status: api_error.code, message: representer.to_json)
end

@ -36,10 +36,7 @@ module API
before do
@category = Category.find(params[:id])
authorize(:view_project, context: @category.project) do
raise API::Errors::NotFound.new(
I18n.t('api_v3.errors.code_404',
type: I18n.t('activerecord.models.category'),
id: params[:id]))
raise API::Errors::NotFound.new(I18n.t('api_v3.errors.code_404'))
end
end

@ -40,10 +40,7 @@ module API
@project = Project.find(params[:id])
authorize(:view_project, context: @project) do
raise API::Errors::NotFound.new(
I18n.t('api_v3.errors.code_404',
type: I18n.t('activerecord.models.project'),
id: params[:id]))
raise API::Errors::NotFound.new(I18n.t('api_v3.errors.code_404'))
end
end

@ -70,8 +70,7 @@ module API
def user_allowed_to_access
unless ::WorkPackage.visible(@user).exists?(model)
message = not_found_error_message('WorkPackage', model.id)
errors.add :error_not_found, message
errors.add :error_not_found, I18n.t('api_v3.errors.code_404')
end
end
@ -122,10 +121,6 @@ module API
def principal_visible?(id, list)
list.exists?(user_id: id)
end
def not_found_error_message(object_type, id)
"Couldn't find #{object_type} with id=#{id}"
end
end
end
end

@ -126,10 +126,7 @@ module API
post do
authorize({ controller: :journals, action: :new },
context: @work_package.project) do
raise API::Errors::NotFound.new(
I18n.t('api_v3.errors.code_404',
type: I18n.t('activerecord.models.work_package'),
id: params[:id]))
raise API::Errors::NotFound.new(I18n.t('api_v3.errors.code_404'))
end
@work_package.journal_notes = params[:comment]

@ -89,24 +89,10 @@ shared_examples_for 'unauthorized access' do
end
shared_examples_for 'not found' do
before do
unless defined?(id) && defined?(type)
message = <<MESSAGE
Required to have specified:
* id
* type
You can use 'let' for that.
MESSAGE
raise message
end
end
it_behaves_like 'error response',
404,
'NotFound' do
let(:message) { I18n.t('api_v3.errors.code_404', type: type, id: id) }
let(:message) { I18n.t('api_v3.errors.code_404') }
end
end

@ -167,10 +167,7 @@ h4. things we like
context 'requesting nonexistent work package' do
let(:get_path) { '/api/v3/work_packages/909090' }
it_behaves_like 'not found' do
let(:id) { 909090 }
let(:type) { 'WorkPackage' }
end
it_behaves_like 'not found'
end
end
@ -221,10 +218,7 @@ h4. things we like
include_context 'patch request'
it_behaves_like 'not found' do
let(:id) { work_package.id }
let(:type) { 'WorkPackage' }
end
it_behaves_like 'not found'
end
context 'no permission to edit the work package' do

@ -64,10 +64,7 @@ describe 'API v3 Work package form resource', type: :request do
let(:current_user) { unauthorized_user }
end
it_behaves_like 'not found' do
let(:id) { work_package.id }
let(:type) { 'WorkPackage' }
end
it_behaves_like 'not found'
end
context 'user with needed permissions' do

Loading…
Cancel
Save