saoshyant 1.0.2 → 1.0.3
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/json_exception_handeler.rb +4 -14
- data/lib/saoshyant.rb +11 -3
- data/saoshyant.gemspec +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: fd5c29ebfd9fde3d52ac9f9901fff2141571550f33365fd2ef9f5062480e7b89
|
|
4
|
+
data.tar.gz: 5e1d8b22a76730545ddc5771149cc5166a11e9e02febb9f3dcb696517184811a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b3ac795f7ccb9cf77ab1ead8b62e3e60fb6160dfb419423643336e98f53f7ab6e7c341c82a455ee46c5858284186b8201b7dcde539a9643343382644a19811a
|
|
7
|
+
data.tar.gz: c2fe5236117d02125f62c50090503aa003bf9824d76a3f5dda510a8ad4d6d89ca535c885ebfe5ffce0812732f6f43d9bad74535f5ffaaffb9f2c702bd7c076c7
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
module Saoshyant
|
|
2
2
|
class JsonExceptionHandeler
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def self.customize(exception_klass, code, log = false)
|
|
7
|
-
validate_arguments code, log
|
|
8
|
-
return if @@exception_klasses.key?(exception_klass)
|
|
9
|
-
|
|
10
|
-
@@exception_klasses.merge!(exception_klass => {code: code, log: log})
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
def self.code_status exception
|
|
15
|
-
@@exception_klasses.key?(exception.class) ? @@exception_klasses[exception.class][:code] : DEFAULT_ERROR_CODE
|
|
4
|
+
def self.code_status exception, exception_klasses
|
|
5
|
+
exception_klasses.key?(exception.class) ? exception_klasses[exception.class][:code] : DEFAULT_ERROR_CODE
|
|
16
6
|
end
|
|
17
7
|
|
|
18
|
-
def self.log_status exception
|
|
19
|
-
|
|
8
|
+
def self.log_status exception, exception_klasses
|
|
9
|
+
exception_klasses.key?(exception.class) ? exception_klasses[exception.class][:log] : false
|
|
20
10
|
end
|
|
21
11
|
|
|
22
12
|
def self.validate_arguments code, log
|
data/lib/saoshyant.rb
CHANGED
|
@@ -4,17 +4,25 @@ require 'json_exception_handeler'
|
|
|
4
4
|
|
|
5
5
|
module Saoshyant
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
|
+
@@exception_klasses = {}
|
|
7
8
|
|
|
8
9
|
DEFAULT_ERROR_CODE = 500
|
|
9
10
|
included do
|
|
10
11
|
rescue_from Exception, with: :render_exception
|
|
11
12
|
end
|
|
12
13
|
|
|
14
|
+
def saoshyant_option(exception_klass, code, log = false)
|
|
15
|
+
Saoshyant::JsonExceptionHandeler.validate_arguments(code, log)
|
|
16
|
+
return if @@exception_klasses.key?(exception_klass)
|
|
17
|
+
|
|
18
|
+
@@exception_klasses.merge!(exception_klass => {code: code, log: log})
|
|
19
|
+
end
|
|
20
|
+
|
|
13
21
|
def render_exception ex
|
|
14
|
-
code = Saoshyant::JsonExceptionHandeler.code_status ex
|
|
15
|
-
log = Saoshyant::JsonExceptionHandeler.log_status ex
|
|
22
|
+
code = Saoshyant::JsonExceptionHandeler.code_status ex, @@exception_klasses
|
|
23
|
+
log = Saoshyant::JsonExceptionHandeler.log_status ex, @@exception_klasses
|
|
16
24
|
|
|
17
25
|
Saoshyant::ExceptionLogger.log(ex.message) if log == true
|
|
18
|
-
|
|
26
|
+
$saoshyant_response.call(code, ex.message, ex.class.inspect)
|
|
19
27
|
end
|
|
20
28
|
end
|
data/saoshyant.gemspec
CHANGED
|
@@ -2,7 +2,7 @@ require 'version'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'saoshyant'
|
|
5
|
-
s.version = '1.0.
|
|
5
|
+
s.version = '1.0.3'
|
|
6
6
|
s.date = '2020-02-10'
|
|
7
7
|
s.summary = "Handle Rails Exception Apis"
|
|
8
8
|
s.description = "when exceptoin raised we dont want see it in ugly and red display, saoshyant present it in json response"
|