passfort 0.2.0 → 0.2.1

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: 11120072e170612a1a224a7e5494a78401ac7c840b9efd54e43c104948f0c9fd
4
- data.tar.gz: 035174f509a2106dd5ea314517ec24b503d6d22b30100c64c935f360b6860396
3
+ metadata.gz: aad8b4d28916b07b98a185e5770cdde81ca59353d71284171eb8d4a5fa4c240b
4
+ data.tar.gz: ef28d85a96a8c5393deb1b8d4a0ba4ed477897239d43a0d5a73294648ffcea88
5
5
  SHA512:
6
- metadata.gz: e5041f41f44de8502abe4b7d3c0b4d59570e5ad629b66c74b10980cad3333c4bb3ce19fbaeb050a3e4a9355caa394df365586c1f883a57746d6546470d290700
7
- data.tar.gz: 94f245e7d800b9bfbf7ca0b40db72f5f37894bd56a8df125858c703cfcd742a00a324c50d28421fc3ccc60e09423ad9d198feae5d3d5b6bb2fef5595600b66a6
6
+ metadata.gz: cf10cfef404e40a8f935fa4e8b68f2f0a1a27517f5a5f4bda1f82ee98e9df192792089a01cd8f02a6a85f51a35088e0745081945c989d0ff887dfb40fc9c91e9
7
+ data.tar.gz: e31d726cf74c4d37b7f9626cf7c647e791ceac7dccfb5d00c49a62cd741249744aea26d7b768f8e740e830eeb303ac2471e771affbefaf7dd47c4f27811ad3e5
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ Unreleased
6
6
 
7
7
  No changes.
8
8
 
9
+ 0.2.1
10
+ -----
11
+
12
+ - Include detailed error information in any raised errors.
13
+
9
14
  0.2.0
10
15
  -----
11
16
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passfort (0.2.0)
4
+ passfort (0.2.1)
5
5
  activesupport (~> 5.0)
6
6
  excon (~> 0.60)
7
7
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "passfort/errors/api_error"
4
+ require "passfort/errors/unknown_api_error"
4
5
  require "passfort/errors/chargeable_limit_reached_error"
5
6
  require "passfort/errors/invalid_api_key_error"
6
7
  require "passfort/errors/invalid_input_data_error"
@@ -4,11 +4,12 @@ module Passfort
4
4
  module Errors
5
5
  # Represents any response from the API which is not a 200 OK
6
6
  class APIError < StandardError
7
- attr_reader :response
7
+ attr_reader :response, :errors
8
8
 
9
- def initialize(msg, response = nil)
9
+ def initialize(msg, errors = [], response = nil)
10
10
  super(msg)
11
11
  @response = response
12
+ @errors = errors
12
13
  end
13
14
  end
14
15
  end
@@ -4,8 +4,8 @@ module Passfort
4
4
  module Errors
5
5
  # Specific error class for when the chargeable limit has been reached
6
6
  class ChargeableLimitReachedError < APIError
7
- def initialize(response = nil)
8
- super("Rate limit exceeded", response)
7
+ def initialize(*args)
8
+ super("Rate limit exceeded", *args)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ module Passfort
4
4
  module Errors
5
5
  # Specific error class for when an invalid API key is used to access the service
6
6
  class InvalidAPIKeyError < APIError
7
- def initialize(response = nil)
8
- super("Invalid API key", response)
7
+ def initialize(*args)
8
+ super("Invalid API key", *args)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ module Passfort
4
4
  module Errors
5
5
  # Specific error class for when an invalid input data is used to query the service
6
6
  class InvalidInputDataError < APIError
7
- def initialize(response = nil)
8
- super("Invalid input data", response)
7
+ def initialize(*args)
8
+ super("Invalid input data", *args)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ module Passfort
4
4
  module Errors
5
5
  # Specific error class for when an HTTP request error has occurred
6
6
  class RequestError < APIError
7
- def initialize(response)
8
- super("Request API error - HTTP #{response.status}", response)
7
+ def initialize(errors, response)
8
+ super("Request API error - HTTP #{response.status}", errors, response)
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Errors
5
+ # Specific error class for when an unknown error is returned
6
+ class UnknownApiError < APIError
7
+ def initialize(*args)
8
+ super("Unknown API error", *args)
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/passfort/http.rb CHANGED
@@ -36,25 +36,22 @@ module Passfort
36
36
  # error codes: https://passfort.com/developer/v4/data-reference/ErrorCodes
37
37
  def handle_error(response, body)
38
38
  unless [200, 201].include?(response.status)
39
- raise Passfort::Errors::RequestError, response
39
+ raise Passfort::Errors::RequestError.new([], response)
40
40
  end
41
41
 
42
42
  errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]
43
43
 
44
- handle_response_error(errors[0], response) if errors.any?
44
+ handle_response_error(errors, response) if errors.any?
45
45
  end
46
46
 
47
- def handle_response_error(error, response)
48
- case error["code"]
49
- when 201
50
- raise Passfort::Errors::InvalidInputDataError, response
51
- when 204
52
- raise Passfort::Errors::InvalidAPIKeyError, response
53
- when 104
54
- raise Passfort::Errors::ChargeableLimitReachedError, response
55
- else
56
- raise Passfort::Errors::APIError.new("Unknown API error", response)
57
- end
47
+ def handle_response_error(errors, response)
48
+ error_class = case errors[0]["code"]
49
+ when 201 then Passfort::Errors::InvalidInputDataError
50
+ when 204 then Passfort::Errors::InvalidAPIKeyError
51
+ when 104 then Passfort::Errors::ChargeableLimitReachedError
52
+ else Passfort::Errors::UnknownApiError
53
+ end
54
+ raise error_class.new(errors, response)
58
55
  end
59
56
  end
60
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passfort
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -18,45 +18,35 @@ RSpec.describe Passfort::Http do
18
18
  let(:status) { 404 }
19
19
  let(:error_class) { Passfort::Errors::RequestError }
20
20
 
21
- it "raises a specific APIError" do
22
- is_expected.to raise_error(instance_of(error_class))
23
- end
21
+ it { is_expected.to raise_error(error_class) }
24
22
  end
25
23
 
26
24
  context "when returning an invalid API Key error" do
27
25
  let(:error_code) { 204 }
28
26
  let(:error_class) { Passfort::Errors::InvalidAPIKeyError }
29
27
 
30
- it "raises a specific APIError" do
31
- is_expected.to raise_error(instance_of(error_class))
32
- end
28
+ it { is_expected.to raise_error(error_class) }
33
29
  end
34
30
 
35
31
  context "when returning an invalid input data error" do
36
32
  let(:error_code) { 201 }
37
33
  let(:error_class) { Passfort::Errors::InvalidInputDataError }
38
34
 
39
- it "raises a specific APIError" do
40
- is_expected.to raise_error(instance_of(error_class))
41
- end
35
+ it { is_expected.to raise_error(error_class) }
42
36
  end
43
37
 
44
38
  context "when returning a chargeable limit reached error" do
45
39
  let(:error_code) { 104 }
46
40
  let(:error_class) { Passfort::Errors::ChargeableLimitReachedError }
47
41
 
48
- it "raises a specific APIError" do
49
- is_expected.to raise_error(instance_of(error_class))
50
- end
42
+ it { is_expected.to raise_error(error_class) }
51
43
  end
52
44
 
53
45
  context "when returning an unknown API error" do
54
46
  let(:error_code) { 203 }
55
- let(:error_class) { Passfort::Errors::APIError }
47
+ let(:error_class) { Passfort::Errors::UnknownApiError }
56
48
 
57
- it "raises a specific APIError" do
58
- is_expected.to raise_error(instance_of(error_class))
59
- end
49
+ it { is_expected.to raise_error(error_class) }
60
50
  end
61
51
 
62
52
  context "when returning a successful result" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passfort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-14 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -135,6 +135,7 @@ files:
135
135
  - lib/passfort/errors/invalid_api_key_error.rb
136
136
  - lib/passfort/errors/invalid_input_data_error.rb
137
137
  - lib/passfort/errors/request_error.rb
138
+ - lib/passfort/errors/unknown_api_error.rb
138
139
  - lib/passfort/http.rb
139
140
  - lib/passfort/resource.rb
140
141
  - lib/passfort/resource/base.rb