minato_error_handler 0.1.2.pre.2 → 0.1.2.pre.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/minato_error_handler/error_handler.rb +17 -5
- data/lib/minato_error_handler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 933cd1db1433ec311e9444e98083fdd941533d15caf2c9a47a50eea92db8458b
|
4
|
+
data.tar.gz: 0135162f0cfd82a5774e53eefb28516068316ea41fca125078496087def6f94c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38ab27987d1a5238ef906ea0d206eb4ef9709128185a22d0ca1f33a3084f7fa006171dc13b8a3b93966bf7ed7ded9ba906e6a29849c43aa12af7b41c1cc80576
|
7
|
+
data.tar.gz: 26ae1501716ab8e63be2c027e4c5c8ee58382a1f89acd30b04c978d448ec04e7bb31dc1d8a51f9bd4c85ce9f18e87213292d34398a1185ef8c1b0eb1aa729884
|
@@ -4,12 +4,10 @@ module MinatoErrorHandler
|
|
4
4
|
module ErrorHandler
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
included do
|
7
|
+
included do |base|
|
8
8
|
rescue_from StandardError, with: :handle
|
9
|
-
end
|
10
9
|
|
11
|
-
|
12
|
-
@default_error_class = klass.to_s.camelize.constantize
|
10
|
+
base.extend ClassMethods
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
@@ -23,7 +21,7 @@ module MinatoErrorHandler
|
|
23
21
|
def parse_error(error)
|
24
22
|
return error if error.is_a?(MinatoErrorHandler::MinatoError)
|
25
23
|
|
26
|
-
error_class =
|
24
|
+
error_class = self.class.default_error_class || MinatoErrorHandler::UnknowError
|
27
25
|
|
28
26
|
minato_error = error_class.new
|
29
27
|
minato_error.caused_by = error.full_message
|
@@ -34,5 +32,19 @@ module MinatoErrorHandler
|
|
34
32
|
def report_error(error)
|
35
33
|
Rails.logger.error(error.as_json)
|
36
34
|
end
|
35
|
+
|
36
|
+
module ClassMethods
|
37
|
+
def default_error(klass)
|
38
|
+
# rubocop:disable Style/ClassVars
|
39
|
+
class_variable_set(:@@default_error_class, klass.to_s.camelize.constantize)
|
40
|
+
# rubocop:enable Style/ClassVars
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_error_class
|
44
|
+
return nil unless class_variable_defined? :@@default_error_class
|
45
|
+
|
46
|
+
class_variable_get(:@@default_error_class)
|
47
|
+
end
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|