diff --git a/lib/api/errors/unwritable_property.rb b/lib/api/errors/unwritable_property.rb index 75c0bdf1f7..b2ecb342f4 100644 --- a/lib/api/errors/unwritable_property.rb +++ b/lib/api/errors/unwritable_property.rb @@ -29,23 +29,13 @@ module API module Errors - class UnwritableProperty < Grape::Exceptions::Base - attr_reader :code, :title, :description, :headers + class UnwritableProperty < ErrorBase + IDENTIFIER = 'urn:openproject-org:api:v3:errors:PropertyIsReadOnly' - def initialize(property, args = { }) - @property = property - @code = args[:code] || 422 - @title = args[:title] || 'unwriteable_property_error' - @description = args[:description] || 'You tried to write read-only property.' - @headers = { 'Content-Type' => 'application/hal+json' }.merge(args[:headers] || { }) - end - - def errors - [{ key: @property, messages: ['is read-only'] }] - end - - def to_json - { title: @title, description: @description, errors: errors }.to_json + def initialize(invalid_attributes) + super 422, + IDENTIFIER, + "You must not write the following attributes: #{invalid_attributes.keys.join(', ')}" end end end diff --git a/lib/api/v3/work_packages/work_packages_api.rb b/lib/api/v3/work_packages/work_packages_api.rb index 88a8df95e6..672e715545 100644 --- a/lib/api/v3/work_packages/work_packages_api.rb +++ b/lib/api/v3/work_packages/work_packages_api.rb @@ -48,7 +48,7 @@ module API attributes = JSON.parse(env['api.request.input']) invalid_attributes = invalid_work_package_update_attributes(attributes) - fail ::API::Errors::Validation.new(nil) unless invalid_attributes.empty? + fail ::API::Errors::UnwritableProperty.new(invalid_attributes) unless invalid_attributes.empty? end def invalid_work_package_update_attributes(attributes)