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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 461025d6d6b837a13f28418ecebc1ad466e799149c2baf5d8f4f7d825971c322
4
- data.tar.gz: b0b2f92dc62d946a9fd1716f328cbe7e5a4162bb99b6feeb29b77977cabe7bb3
3
+ metadata.gz: fd5c29ebfd9fde3d52ac9f9901fff2141571550f33365fd2ef9f5062480e7b89
4
+ data.tar.gz: 5e1d8b22a76730545ddc5771149cc5166a11e9e02febb9f3dcb696517184811a
5
5
  SHA512:
6
- metadata.gz: 5a011a4f7d9fedce5dae96bcbbaff0bec49e9053e0a08dc5175d6de31a987bb25a6ac92ed7a9a944ad68c4a67d46609edbd5029c6ffd9623d7f531e42773e487
7
- data.tar.gz: 7f202cc6d9163b312113d937b40d36be3b3e56631806748a6434c284f68773bfddab5a7d2f1781e46c14ea8425cbd48924f80f8b35dd21f9067f131684dfee00
6
+ metadata.gz: 9b3ac795f7ccb9cf77ab1ead8b62e3e60fb6160dfb419423643336e98f53f7ab6e7c341c82a455ee46c5858284186b8201b7dcde539a9643343382644a19811a
7
+ data.tar.gz: c2fe5236117d02125f62c50090503aa003bf9824d76a3f5dda510a8ad4d6d89ca535c885ebfe5ffce0812732f6f43d9bad74535f5ffaaffb9f2c702bd7c076c7
@@ -1,22 +1,12 @@
1
1
  module Saoshyant
2
2
  class JsonExceptionHandeler
3
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
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
- @@exception_klasses.key?(exception.class) ? @@exception_klasses[exception.class][:log] : false
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
@@ -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
- render json: {status: 'error', :message => ex.message, :exception_type => ex.class.inspect}, status: code
26
+ $saoshyant_response.call(code, ex.message, ex.class.inspect)
19
27
  end
20
28
  end
@@ -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.2'
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"
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: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Majid Imanzade