saoshyant 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rackfile +8 -0
- data/lib/json_exception_handeler.rb +27 -0
- data/lib/saoshyant.rb +6 -5
- data/saoshyant.gemspec +2 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a61410a83892b4511dc858709e1033c89da482294e1f1d6f82f8a2b1c207ace4
|
4
|
+
data.tar.gz: 5a737800386ce2c20444b6ed92d89ed3e75fb4f8e47b73f69c1e8dd8e2e44f54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f24478979654ab6feea4b97d6c97749405f532b52298cc13ba701f4a7d69792184dc00467d2f11004d93a12b7011fcb7431553a53740e774d9460199cfe1911e
|
7
|
+
data.tar.gz: 655f889ffbc6a39ac65a56a32a13dd25221624b438459b6eb0621a34770fa8f3658f91365e6dbd73b6440c2f9b4764bd2fe9201f60baaf9b957dbc1b10d0efe6
|
data/Rackfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Saoshyant
|
2
|
+
class JsonExceptionHandeler
|
3
|
+
|
4
|
+
@@exception_klasses = {}
|
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
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.log_status exception
|
19
|
+
@@exception_klasses.key?(exception.class) ? @@exception_klasses[exception.class][:log] : false
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.validate_arguments code, log
|
23
|
+
raise "Invalid code status" unless code.kind_of?(Integer)
|
24
|
+
raise "Invalid log status, it should be Boolean" unless !!log == log
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/saoshyant.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'exception_logger'
|
3
|
+
require 'json_exception_handeler'
|
3
4
|
|
4
5
|
module Saoshyant
|
5
6
|
extend ActiveSupport::Concern
|
@@ -9,11 +10,11 @@ module Saoshyant
|
|
9
10
|
rescue_from Exception, with: :render_exception
|
10
11
|
end
|
11
12
|
|
12
|
-
def render_exception
|
13
|
-
code =
|
14
|
-
log =
|
13
|
+
def render_exception ex
|
14
|
+
code = Saoshyant::JsonExceptionHandeler.code_status ex
|
15
|
+
log = Saoshyant::JsonExceptionHandeler.log_status ex
|
15
16
|
|
16
|
-
Saoshyant::
|
17
|
-
render json: {:message =>
|
17
|
+
Saoshyant::ExceptionLogger.log(ex.message) if log == true
|
18
|
+
render json: {status: 'error', :message => ex.message, :exception_type => ex.class.inspect}, status: code
|
18
19
|
end
|
19
20
|
end
|
data/saoshyant.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'saoshyant'
|
5
|
-
s.version = '
|
5
|
+
s.version = '1.0.1'
|
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"
|
@@ -13,4 +13,4 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.require_paths = ['lib']
|
16
|
-
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saoshyant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Majid Imanzade
|
@@ -19,7 +19,9 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
21
|
- Gemfile
|
22
|
+
- Rackfile
|
22
23
|
- lib/exception_logger.rb
|
24
|
+
- lib/json_exception_handeler.rb
|
23
25
|
- lib/saoshyant.rb
|
24
26
|
- lib/version.rb
|
25
27
|
- saoshyant.gemspec
|