Skip to content

Commit cc7882b

Browse files
author
Sebastian Wilgosz
committed
Extract predefined error definition to a constant
1 parent 70878ce commit cc7882b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/jsonapi_errors_handler.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
require 'jsonapi_errors_handler/error_serializer'
88

99
module JsonapiErrorsHandler
10+
PREDEFINED_HASH = {
11+
'JsonapiErrorsHandler::Errors::Invalid' =>
12+
'JsonapiErrorsHandler::Errors::Invalid',
13+
'JsonapiErrorsHandler::Errors::Forbidden' =>
14+
'JsonapiErrorsHandler::Errors::Forbidden',
15+
'JsonapiErrorsHandler::Errors::NotFound' => '
16+
JsonapiErrorsHandler::Errors::NotFound',
17+
'JsonapiErrorsHandler::Errors::Unauthorized' =>
18+
'JsonapiErrorsHandler::Errors::Unauthorized'
19+
}.freeze
20+
1021
def self.included(base)
1122
base.class_eval do
12-
ErrorMapper.map_errors!(
13-
'JsonapiErrorsHandler::Errors::Invalid' => 'JsonapiErrorsHandler::Errors::Invalid',
14-
'JsonapiErrorsHandler::Errors::Forbidden' => 'JsonapiErrorsHandler::Errors::Forbidden',
15-
'JsonapiErrorsHandler::Errors::NotFound' => 'JsonapiErrorsHandler::Errors::NotFound',
16-
'JsonapiErrorsHandler::Errors::Unauthorized' => 'JsonapiErrorsHandler::Errors::Unauthorized'
17-
)
23+
ErrorMapper.map_errors!(PREDEFINED_HASH)
1824
end
1925
end
2026

0 commit comments

Comments
 (0)