basecrm 1.3.1 → 1.3.2

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: 88761921e923b850ccbc638210030e189d127c78b6311cfc80b77d627d2330b0
4
- data.tar.gz: 5dd57f40287add6123640959a273d7492fa6fa3ad7a3a7df8db8f5f560605371
3
+ metadata.gz: a9b11989ce99c253d1924a4cf9994e941d28c003d2f4af414224bc0b05990b82
4
+ data.tar.gz: 129afc0658fb9f5320fef56bc3f243651e4725ce485a94976c22b3c4c5f0c1f8
5
5
  SHA512:
6
- metadata.gz: bee7621373635902f674517cf4a88d3342968b51a559971ace04d1f6e79dcd57f3c7cfb9af09a166f7c5acaeff10559cc97f7b3a9bdcc0dbb2490d50c5c52590
7
- data.tar.gz: 3f022e27eb46babad11cc02e9a4479f714851fb0c5a31e62e13cd3c2351ca22afce0960b81a7717b2456bf028e1e710ceafb4aa432bdb149c093dad85e71fa04
6
+ metadata.gz: 5330a0039bced2ce1aca5bbb078f8698e495737a41d14a63682638d7cddf4633c9d290cd402ff8e03a34fbffce4c758d0f768bbb1c870fa54d23f6253808eaf8
7
+ data.tar.gz: d2bfcdf4ad1868f75bf24ca628c7cf2739391730f99173de9e8068932dec3b6420327e7413fc4a7238b559d043e88f6369ef64573d2e5c778135b650ee0ef0b0
@@ -8,9 +8,6 @@ module BaseCRM
8
8
 
9
9
  content_type = env[:response_headers]['content-type']
10
10
 
11
- unless content_type.include?('json')
12
- raise "status=#{status} error=Unknown error occurred."
13
- end
14
11
 
15
12
  error_klass = case status
16
13
  when 422 then BaseCRM::ResourceError
@@ -18,7 +15,12 @@ module BaseCRM
18
15
  when 500...600 then BaseCRM::ServerError
19
16
  end
20
17
 
21
- raise errors_collection(env, error_klass)
18
+ if !content_type.nil? && content_type.include?('json')
19
+ raise errors_collection(env, error_klass)
20
+ else
21
+ error = {:error=>{:code=>status, :message=>"Unknown error occurred."}, :meta=>{}}
22
+ raise error_klass.new(error)
23
+ end
22
24
  end
23
25
 
24
26
  def errors_collection(env, error_klass)
@@ -1,3 +1,3 @@
1
1
  module BaseCRM
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe BaseCRM::Middlewares::RaiseError do
4
+ before { @raise_error = BaseCRM::Middlewares::RaiseError.new }
5
+
6
+ describe :on_complete do
7
+
8
+ it "returns nil when code 200..300" do
9
+ expect { @raise_error.on_complete({:status => 204}) }.not_to raise_error
10
+ end
11
+
12
+ it "raises ResourceError when code 422 and no content type" do
13
+ expect { @raise_error.on_complete({:status => 422, :response_headers => {}}) }
14
+ .to raise_error do |error|
15
+ expect(error).to be_a(BaseCRM::ResourceError)
16
+ expect(error.code).to eql(422)
17
+ expect(error.message).to eql("Unknown error occurred.")
18
+ end
19
+ end
20
+
21
+ it "raises RequestError when code 400..500 and no content type" do
22
+ expect { @raise_error.on_complete({:status => 400, :response_headers => {}}) }
23
+ .to raise_error do |error|
24
+ expect(error).to be_a(BaseCRM::RequestError)
25
+ expect(error.code).to eql(400)
26
+ expect(error.message).to eql("Unknown error occurred.")
27
+ end
28
+ end
29
+
30
+ it "raises ServerError when code 500..600 and no content type" do
31
+ expect { @raise_error.on_complete({:status => 500, :response_headers => {}}) }
32
+ .to raise_error do |error|
33
+ expect(error).to be_a(BaseCRM::ServerError)
34
+ expect(error.code).to eql(500)
35
+ expect(error.message).to eql("Unknown error occurred.")
36
+ end
37
+ end
38
+
39
+ it "raises ResourceError when code 422 and XML (not supported) content type" do
40
+ expect { @raise_error.on_complete({:status => 422, :response_headers => {'content-type' => "application/xml"}}) }
41
+ .to raise_error do |error|
42
+ expect(error).to be_a(BaseCRM::ResourceError)
43
+ expect(error.code).to eql(422)
44
+ expect(error.message).to eql("Unknown error occurred.")
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - BaseCRM developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-08 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -193,6 +193,7 @@ files:
193
193
  - spec/factories/source.rb
194
194
  - spec/factories/tag.rb
195
195
  - spec/factories/task.rb
196
+ - spec/middlewares/raise_error_spec.rb
196
197
  - spec/models/sync_meta_spec.rb
197
198
  - spec/services/accounts_service_spec.rb
198
199
  - spec/services/associated_contacts_service_spec.rb
@@ -243,6 +244,7 @@ specification_version: 4
243
244
  summary: BaseCRM Official API V2 library client for ruby
244
245
  test_files:
245
246
  - spec/spec_helper.rb
247
+ - spec/middlewares/raise_error_spec.rb
246
248
  - spec/utils/coercion_spec.rb
247
249
  - spec/utils/coercion.rb
248
250
  - spec/models/sync_meta_spec.rb