saoshyant 1.0.3 → 1.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: fd5c29ebfd9fde3d52ac9f9901fff2141571550f33365fd2ef9f5062480e7b89
4
- data.tar.gz: 5e1d8b22a76730545ddc5771149cc5166a11e9e02febb9f3dcb696517184811a
3
+ metadata.gz: 3f799681f89ad3b560a80e46485547b9eb1e471f70d687682af05bbe6fa06f67
4
+ data.tar.gz: 9fc6cddcd7ba72e262585299dc2df801ae6de83858a41a08c67388e7788c0a15
5
5
  SHA512:
6
- metadata.gz: 9b3ac795f7ccb9cf77ab1ead8b62e3e60fb6160dfb419423643336e98f53f7ab6e7c341c82a455ee46c5858284186b8201b7dcde539a9643343382644a19811a
7
- data.tar.gz: c2fe5236117d02125f62c50090503aa003bf9824d76a3f5dda510a8ad4d6d89ca535c885ebfe5ffce0812732f6f43d9bad74535f5ffaaffb9f2c702bd7c076c7
6
+ metadata.gz: '085dc244ff5d1f39092c1568408cc3357ea83b902385fd5ca03b320a71d68e5733c195bc9fdacba3a909aad0ef56e595ed7fecda3606bb1a3dbda7fe4c757cac'
7
+ data.tar.gz: e6bbe044e9a8b17dc046f60ffde6c0210bb639c68c2b60730fbf9ff150cc44df75f13ccd6e40f1d3407a987d16eef2cddb02b288dd8ddabe49e0ff9dceea6674
@@ -1,5 +1,7 @@
1
1
  module Saoshyant
2
- class JsonExceptionHandeler
2
+ class ExceptionHandler
3
+
4
+ DEFAULT_ERROR_CODE = 500
3
5
 
4
6
  def self.code_status exception, exception_klasses
5
7
  exception_klasses.key?(exception.class) ? exception_klasses[exception.class][:code] : DEFAULT_ERROR_CODE
@@ -1,26 +1,27 @@
1
1
  require 'rails'
2
2
  require 'exception_logger'
3
- require 'json_exception_handeler'
3
+ require 'exception_handler'
4
4
 
5
5
  module Saoshyant
6
6
  extend ActiveSupport::Concern
7
+ include ActiveSupport::Rescuable
8
+
7
9
  @@exception_klasses = {}
8
10
 
9
- DEFAULT_ERROR_CODE = 500
10
11
  included do
11
- rescue_from Exception, with: :render_exception
12
+ rescue_from Exception, with: :execute_exception
12
13
  end
13
14
 
14
15
  def saoshyant_option(exception_klass, code, log = false)
15
- Saoshyant::JsonExceptionHandeler.validate_arguments(code, log)
16
+ Saoshyant::ExceptionHandler.validate_arguments(code, log)
16
17
  return if @@exception_klasses.key?(exception_klass)
17
18
 
18
19
  @@exception_klasses.merge!(exception_klass => {code: code, log: log})
19
20
  end
20
21
 
21
- def render_exception ex
22
- code = Saoshyant::JsonExceptionHandeler.code_status ex, @@exception_klasses
23
- log = Saoshyant::JsonExceptionHandeler.log_status ex, @@exception_klasses
22
+ def execute_exception ex
23
+ code = Saoshyant::ExceptionHandler.code_status ex, @@exception_klasses
24
+ log = Saoshyant::ExceptionHandler.log_status ex, @@exception_klasses
24
25
 
25
26
  Saoshyant::ExceptionLogger.log(ex.message) if log == true
26
27
  $saoshyant_response.call(code, ex.message, ex.class.inspect)
@@ -1,8 +1,6 @@
1
- require 'version'
2
-
3
1
  Gem::Specification.new do |s|
4
2
  s.name = 'saoshyant'
5
- s.version = '1.0.3'
3
+ s.version = '1.1'
6
4
  s.date = '2020-02-10'
7
5
  s.summary = "Handle Rails Exception Apis"
8
6
  s.description = "when exceptoin raised we dont want see it in ugly and red display, saoshyant present it in json response"
@@ -1,13 +1,14 @@
1
1
  require 'spec_helper'
2
+ include Saoshyant
2
3
 
3
4
  describe Saoshyant do
4
5
  describe 'JsonExceptionHandeler' do
5
6
  it 'expect get error for invalid code status' do
6
- expect{ Saoshyant::JsonExceptionHandeler.customize(NameError, '200', false) }.to raise_error(RuntimeError)
7
+ expect{ saoshyant_option(NameError, '200', false) }.to raise_error(RuntimeError)
7
8
  end
8
9
 
9
10
  it 'expect get error for invalid log status' do
10
- expect{ Saoshyant::JsonExceptionHandeler.customize(NameError, 203, 'true') }.to raise_error(RuntimeError)
11
+ expect{ saoshyant_option(NameError, 203, 'true') }.to raise_error(RuntimeError)
11
12
  end
12
13
  end
13
14
  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: 1.0.3
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Majid Imanzade
@@ -63,8 +63,8 @@ files:
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
65
  - Gemfile
66
+ - lib/exception_handler.rb
66
67
  - lib/exception_logger.rb
67
- - lib/json_exception_handeler.rb
68
68
  - lib/saoshyant.rb
69
69
  - saoshyant.gemspec
70
70
  - spec/saoshyant_test.rb