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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 485baa3c186fc7b8e07b473e9bd065cd8e1920ac1007d3724850f898245289fb
4
- data.tar.gz: 77f6240f7aea6db393e7e45521d1120d90cd623e58a9f89de9f1618a3bf441b8
3
+ metadata.gz: a61410a83892b4511dc858709e1033c89da482294e1f1d6f82f8a2b1c207ace4
4
+ data.tar.gz: 5a737800386ce2c20444b6ed92d89ed3e75fb4f8e47b73f69c1e8dd8e2e44f54
5
5
  SHA512:
6
- metadata.gz: 87d8930e77392ebadc6648975a42bee4076be78f1ed47a75f7435dfb52edf2be91210f3956f16ccc979c45f87a8fd8f584b219df1800fa708531a88c40df61fb
7
- data.tar.gz: 8c23bf5fae6955ce874c4751448a8cd3a727292e413dc320a3724ab1655a10ff979eb7738f0fdb5dfdd87f71ee91a34e8b5a2a9558764f5bea8121c0ed5cd958
6
+ metadata.gz: f24478979654ab6feea4b97d6c97749405f532b52298cc13ba701f4a7d69792184dc00467d2f11004d93a12b7011fcb7431553a53740e774d9460199cfe1911e
7
+ data.tar.gz: 655f889ffbc6a39ac65a56a32a13dd25221624b438459b6eb0621a34770fa8f3658f91365e6dbd73b6440c2f9b4764bd2fe9201f60baaf9b957dbc1b10d0efe6
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -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
@@ -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 exception
13
- code = exception.respond_to?(:code) ? exception&.code : DEFAULT_ERROR_CODE
14
- log = exception.respond_to?(:log)
13
+ def render_exception ex
14
+ code = Saoshyant::JsonExceptionHandeler.code_status ex
15
+ log = Saoshyant::JsonExceptionHandeler.log_status ex
15
16
 
16
- Saoshyant::MajidLogger.log(exception.message) if log == true
17
- render json: {:message => exception.message}, status: code
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'saoshyant'
5
- s.version = '0.0.1'
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: 0.0.1
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