Skip to content

Commit

Permalink
Extract predefined error definition to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Wilgosz committed Sep 21, 2020
1 parent 70878ce commit cc7882b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/jsonapi_errors_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
require 'jsonapi_errors_handler/error_serializer'

module JsonapiErrorsHandler
PREDEFINED_HASH = {
'JsonapiErrorsHandler::Errors::Invalid' =>
'JsonapiErrorsHandler::Errors::Invalid',
'JsonapiErrorsHandler::Errors::Forbidden' =>
'JsonapiErrorsHandler::Errors::Forbidden',
'JsonapiErrorsHandler::Errors::NotFound' => '
JsonapiErrorsHandler::Errors::NotFound',
'JsonapiErrorsHandler::Errors::Unauthorized' =>
'JsonapiErrorsHandler::Errors::Unauthorized'
}.freeze

def self.included(base)
base.class_eval do
ErrorMapper.map_errors!(
'JsonapiErrorsHandler::Errors::Invalid' => 'JsonapiErrorsHandler::Errors::Invalid',
'JsonapiErrorsHandler::Errors::Forbidden' => 'JsonapiErrorsHandler::Errors::Forbidden',
'JsonapiErrorsHandler::Errors::NotFound' => 'JsonapiErrorsHandler::Errors::NotFound',
'JsonapiErrorsHandler::Errors::Unauthorized' => 'JsonapiErrorsHandler::Errors::Unauthorized'
)
ErrorMapper.map_errors!(PREDEFINED_HASH)
end
end

Expand Down

0 comments on commit cc7882b

Please sign in to comment.