radar-app 0.10.1 → 0.11.0

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: 0fc7c23d9c244a3aa5effcf0c10b5db8f0e90a79c5078fca953226ca0f4957e5
4
- data.tar.gz: 4a47ba93d9e888d3248a5ee5fe32175ee419a4c97af7220d5cae2a42bfbd8e98
3
+ metadata.gz: 4f8b5eb2ee9036a6bc9dad92320b9e837dcb2829577e8e00e30d3e407916345d
4
+ data.tar.gz: 599ab1c560a809e1ba9d093df8b154a8eecc72fa834349452eefcc7fc49d0b08
5
5
  SHA512:
6
- metadata.gz: fb4ef8f00116fb78644094a7d1181c0f4de2bd5aa6090c0a2b0b317ad07becffdc489221cd3e079a662b0d95998d004944b5da63f6f75065a6b9d2d6cf26ddd4
7
- data.tar.gz: 1190365b21e65d99940dfe0cfca2aeffed244ccb4a2b85a8e09f091948f954368199af609393bf56467d958a44f50a32858c9c7955b44b33124fe39921020a47
6
+ metadata.gz: 887fc9bafe9bb8cd0cc71b0c103886cf58cffac7b2d1a4c6e664e01c76ab2b8df235ddb26b9c73da43c2735f093185e7709a2e53bc57e657a916dee9ef5501e3
7
+ data.tar.gz: 324ef90a6f60bf67375f602560812b23a760cfe4141313c5335e9c1d7a2d58f37442ec6df0e6a16990dd73b322812fe09af01fd994690103f6449f62583feaaa
@@ -1,10 +1,34 @@
1
1
  require 'thrift/exceptions'
2
+ require 'radar-api'
2
3
 
3
4
  module Radar
4
5
  module App
5
6
  module ProcessorFactory
7
+
8
+ class AppErrorHandler
9
+ def initialize(target)
10
+ @target = target
11
+ end
12
+
13
+ def method_missing(m, *args, &block)
14
+ begin
15
+ @target.send(m, *args, &block)
16
+ rescue => e
17
+ if e.kind_of?(Thrift::Exception)
18
+ raise e
19
+ else
20
+ raise Radar::API::ApplicationError.new(message: e.message, stacktrace: e.backtrace)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
6
26
  def self.create_processor(superclass)
7
27
  Class.new(superclass) do
28
+ def initialize(handler)
29
+ super(AppErrorHandler.new(handler))
30
+ end
31
+
8
32
  def write_error(err, oprot, name, seqid)
9
33
  super
10
34
  raise if err.type == Thrift::ApplicationException::INTERNAL_ERROR
@@ -1,5 +1,5 @@
1
1
  module Radar
2
2
  module App
3
- VERSION = "0.10.1"
3
+ VERSION = "0.11.0"
4
4
  end
5
5
  end
@@ -1,11 +1,31 @@
1
1
  require 'radar/app/processor_factory'
2
2
 
3
3
  describe Radar::App::ProcessorFactory do
4
+ let(:handler_class) do
5
+ Class.new do
6
+ end
7
+ end
4
8
 
5
9
  let(:parent_processor_class) do
6
10
  Class.new do
7
11
  attr_reader :write_error_called
8
12
 
13
+ def raise_an_error
14
+ raise 'an error'
15
+ end
16
+
17
+ def initialize(handler)
18
+ end
19
+
20
+ def process_an_error
21
+ begin
22
+ raise 'an error'
23
+ rescue => e
24
+ x = Thrift::ApplicationException.new(Thrift::ApplicationException::INTERNAL_ERROR, 'Internal error')
25
+ write_error(x, nil, nil, nil)
26
+ end
27
+ end
28
+
9
29
  def process_an_error
10
30
  begin
11
31
  raise 'an error'
@@ -29,7 +49,7 @@ describe Radar::App::ProcessorFactory do
29
49
 
30
50
  describe '#create_processor' do
31
51
  describe 'it creates a processor that' do
32
- let(:processor) { Radar::App::ProcessorFactory.create_processor(parent_processor_class).new }
52
+ let(:processor) { Radar::App::ProcessorFactory.create_processor(parent_processor_class).new(nil) }
33
53
  it 'raises the exception on error' do
34
54
  expect { processor.process_an_error }.to raise_error 'an error'
35
55
  end
@@ -48,4 +68,22 @@ describe Radar::App::ProcessorFactory do
48
68
  end
49
69
  end
50
70
  end
71
+ describe 'AppErrorHandler' do
72
+ let(:error_handler) { Radar::App::ProcessorFactory::AppErrorHandler.new }
73
+ let(:target) { double() }
74
+ context 'then target raises a non-Thrift exception' do
75
+ it 'raises an ApplicationError' do
76
+ allow(target).to receive(:raise_an_error).and_raise 'an error'
77
+ error_handler = Radar::App::ProcessorFactory::AppErrorHandler.new(target)
78
+ expect { error_handler.raise_an_error }.to raise_error(Radar::Api::ApplicationError)
79
+ end
80
+ context 'then target raises a Thrift exception' do
81
+ it 'raises the original error' do
82
+ allow(target).to receive(:raise_an_error).and_raise Radar::Api::AuthenticationError.new
83
+ error_handler = Radar::App::ProcessorFactory::AppErrorHandler.new(target)
84
+ expect { error_handler.raise_an_error }.to raise_error(Radar::Api::AuthenticationError)
85
+ end
86
+ end
87
+ end
88
+ end
51
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radar-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Mendonca
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-06 00:00:00.000000000 Z
12
+ date: 2019-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubygems_version: 3.0.4
236
+ rubygems_version: 3.0.6
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: radar-app generator