beyond_api 0.10.0.pre → 0.11.0.pre

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: 70c9bf9ccb3e7a42a71c8d5a092e0af6969842daf91a7219398b9f5516836cfe
4
- data.tar.gz: d976cda9fdcc8df93394b3b9ad678453db3634a096c6832208e8fe49c917198b
3
+ metadata.gz: 78c3366e77c86e546074cbbc049e2161b231511deede234a92f96d315575ba45
4
+ data.tar.gz: f8e08acff7d5f80be7ffd249c83d6116abd86ddfb216e5c25e955deaffe439be
5
5
  SHA512:
6
- metadata.gz: 94e86e146eb7ed0696efbb7bf7a61e1ade093ba00571ef140e0fb019c6708680d8a26b3b0bc8295e3f30a1327b362b44b0b56b7b474973a975fd212e61317c90
7
- data.tar.gz: 68cc2ad0ec1a9d855dc22c52ca4b5f9a1a76af244eeccc406bb7e384b72267c476f99db47652b34653a9d297836e7637ac9856e60eab09961eec7ea6e8733688
6
+ metadata.gz: f4f0be05bb0c55da87c1c650b86f112993ce8346f6178f3cf27d865d8415377924263d0b2ec648b8a1d8026c6a5a4250221a8dc68ba39bd154bfb43c0913649c
7
+ data.tar.gz: 8400df3f3b61240c0516fc4d86e386eea7e67f88ca56324e68989f731d415e77ab9907817b092dc59c87f79794d96d1e7a76960e4785ebf0237b384ca6ed64e7
@@ -1,3 +1,9 @@
1
+ ### v0.11.0.pre
2
+
3
+ * enhancements
4
+ * Improve error handling class
5
+ * Improve `BeyondApi::Error` class
6
+
1
7
  ### v0.10.0.pre
2
8
 
3
9
  * features
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.10.0.pre)
4
+ beyond_api (0.11.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -1,14 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BeyondApi
4
- class Error
5
- attr_reader :error_id, :details, :message, :trace_id
4
+ class Error < StandardError
5
+ attr_reader :error_id, :details, :trace_id, :full_message, :status_code
6
6
 
7
- def initialize(data)
8
- @error_id = data['errorId']
9
- @details = data['details']
10
- @message = data['message']
11
- @trace_id = data['traceId']
7
+ def initialize(data, status_code = nil)
8
+ @error_id = data['errorId']
9
+ @details = data['details']
10
+ @trace_id = data['traceId']
11
+ @full_message = data
12
+ @status_code = status_code
13
+
14
+ super(data['message'])
12
15
  end
13
16
  end
14
17
  end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "beyond_api/utils"
4
+
3
5
  module BeyondApi
4
6
  class Token
5
7
  class InvalidSessionError < StandardError; end
6
8
 
9
+ include BeyondApi::Utils
10
+
7
11
  attr_reader :session
8
12
 
9
13
  def initialize(session)
@@ -44,7 +48,7 @@ module BeyondApi
44
48
  @session.refresh_token = response["refresh_token"]
45
49
  @session
46
50
  else
47
- BeyondApi::Error.new(response)
51
+ handle_error(response, status)
48
52
  end
49
53
  end
50
54
  end
@@ -10,11 +10,16 @@ module BeyondApi
10
10
  response = sanitize_response(response)
11
11
  BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
12
12
  else
13
- BeyondApi.logger.error "[Beyond API] #{response}"
14
- BeyondApi.configuration.raise_error_requests ? raise(response.to_s) : BeyondApi::Error.new(response)
13
+ handle_error(response, status)
15
14
  end
16
15
  end
17
16
 
17
+ def handle_error(response, status)
18
+ BeyondApi.logger.error "[Beyond API] #{status}: #{response}"
19
+ error = BeyondApi::Error.new(response, status)
20
+ BeyondApi.configuration.raise_error_requests ? raise(error) : error
21
+ end
22
+
18
23
  def to_object_struct(data)
19
24
  if data.is_a? Hash
20
25
  return OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
@@ -1,3 +1,3 @@
1
1
  module BeyondApi
2
- VERSION = "0.10.0.pre".freeze
2
+ VERSION = "0.11.0.pre".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.pre
4
+ version: 0.11.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-05-15 00:00:00.000000000 Z
13
+ date: 2020-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler