Merge pull request #3030 from machisuji/fix/api_null_identifier

refactored huge switch; fixed null id. in dev mode
pull/3174/head
Azure7111 9 years ago
commit 2589147cfe
  1. 2
      lib/api/errors/conflict.rb
  2. 7
      lib/api/errors/error_base.rb
  3. 2
      lib/api/errors/invalid_render_context.rb
  4. 2
      lib/api/errors/invalid_request_body.rb
  5. 2
      lib/api/errors/invalid_user_status_transition.rb
  6. 2
      lib/api/errors/not_found.rb
  7. 2
      lib/api/errors/parse_error.rb
  8. 2
      lib/api/errors/property_format_error.rb
  9. 2
      lib/api/errors/unauthenticated.rb
  10. 2
      lib/api/errors/unauthorized.rb
  11. 2
      lib/api/errors/unsupported_media_type.rb
  12. 2
      lib/api/errors/unwritable_property.rb
  13. 2
      lib/api/errors/validation.rb
  14. 25
      lib/api/v3/errors/error_representer.rb

@ -30,6 +30,8 @@
module API
module Errors
class Conflict < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:UpdateConflict'
def initialize
super 409, I18n.t('api_v3.errors.code_409')
end

@ -52,6 +52,13 @@ module API
::API::Errors::Validation.new(messages_by_attribute.values.map(&:message))
end
##
# Allows defining this error class's identifier once.
# Used to read it otherwise.
def self.identifier(identifier = nil)
@identifier ||= identifier
end
def initialize(code, message)
@code = code
@message = message

@ -30,6 +30,8 @@
module API
module Errors
class InvalidRenderContext < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:InvalidRenderContext'
def initialize(message)
super 400, message
end

@ -30,6 +30,8 @@
module API
module Errors
class InvalidRequestBody < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:InvalidRequestBody'
def initialize(message)
super 400, message
end

@ -30,6 +30,8 @@
module API
module Errors
class InvalidUserStatusTransition < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:InvalidUserStatusTransition'
def initialize
super 400, I18n.t('api_v3.errors.invalid_user_status_transition')
end

@ -30,6 +30,8 @@
module API
module Errors
class NotFound < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:NotFound'
def initialize(message = I18n.t('api_v3.errors.code_404'))
super 404, message
end

@ -30,6 +30,8 @@
module API
module Errors
class ParseError < InvalidRequestBody
identifier InvalidRequestBody.identifier
def initialize(message: I18n.t('api_v3.errors.invalid_json'), details: nil)
super(message)

@ -30,6 +30,8 @@
module API
module Errors
class PropertyFormatError < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:PropertyFormatError'
def initialize(property, expected_format, actual_value)
message = I18n.t('api_v3.errors.invalid_format',
property: property,

@ -30,6 +30,8 @@
module API
module Errors
class Unauthenticated < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:Unauthenticated'
def initialize(message = I18n.t('api_v3.errors.code_401'))
super 401, message
end

@ -30,6 +30,8 @@
module API
module Errors
class Unauthorized < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:MissingPermission'
def initialize
super 403, I18n.t('api_v3.errors.code_403')
end

@ -30,6 +30,8 @@
module API
module Errors
class UnsupportedMediaType < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:TypeNotSupported'
def initialize(message)
super 415, message
end

@ -30,6 +30,8 @@
module API
module Errors
class UnwritableProperty < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:PropertyIsReadOnly'
def initialize(invalid_attributes)
attributes = Array(invalid_attributes)

@ -30,6 +30,8 @@
module API
module Errors
class Validation < ErrorBase
identifier 'urn:openproject-org:api:v3:errors:PropertyConstraintViolation'
def self.create(errors)
merge_error_properties(errors)

@ -57,30 +57,7 @@ module API
def error_identifier
return 'urn:openproject-org:api:v3:errors:MultipleErrors' unless Array(represented.errors).empty?
case represented
when ::API::Errors::Conflict
'urn:openproject-org:api:v3:errors:UpdateConflict'
when ::API::Errors::NotFound
'urn:openproject-org:api:v3:errors:NotFound'
when ::API::Errors::Unauthenticated
'urn:openproject-org:api:v3:errors:Unauthenticated'
when ::API::Errors::Unauthorized
'urn:openproject-org:api:v3:errors:MissingPermission'
when ::API::Errors::UnwritableProperty
'urn:openproject-org:api:v3:errors:PropertyIsReadOnly'
when ::API::Errors::PropertyFormatError
'urn:openproject-org:api:v3:errors:PropertyFormatError'
when ::API::Errors::Validation
'urn:openproject-org:api:v3:errors:PropertyConstraintViolation'
when ::API::Errors::InvalidRenderContext
'urn:openproject-org:api:v3:errors:InvalidRenderContext'
when ::API::Errors::InvalidUserStatusTransition
'urn:openproject-org:api:v3:errors:InvalidUserStatusTransition'
when ::API::Errors::InvalidRequestBody
'urn:openproject-org:api:v3:errors:InvalidRequestBody'
when ::API::Errors::UnsupportedMediaType
'urn:openproject-org:api:v3:errors:TypeNotSupported'
end
represented.class.identifier if represented.class.respond_to?(:identifier)
end
end
end

Loading…
Cancel
Save