kaze_client 0.3.0 → 0.3.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: f04fc270f92f58f489ff092c78adb05ec7d8d241277d2294e1d7d88ddd47e5ef
4
- data.tar.gz: 69a336ea1b82c2a97c6a079a70220a625dfd48da3a3223a637e8c3d4a1e3bde3
3
+ metadata.gz: 483e914296f78875d5a5eb30e3207f7f99d8db4c7bfddbc8440f3983e99f5605
4
+ data.tar.gz: ebb0a204c158f59fa6cdde4d04573b1beaeaa94b07f86b8b7815ce59c9e40ca0
5
5
  SHA512:
6
- metadata.gz: 44e207d6ccb69a208c5273d63e62615d113c0a8b0cf2bcd5020e5b977312ca79125740e29746e2375b18f32c5cdbfe0c70289e3c261e0f5b64c3fefcbd070468
7
- data.tar.gz: bb1088a6628adca37f824660306ea5d4053f86df96f453fea12b02893f37c53e229fb3f7de1d0698cc15fd17d0a8ec4788037327315fb4c599e38462b6d874b6
6
+ metadata.gz: c3006d994cb61c5b180449f58dce770ddb7f12cf3636cb3247b2b669f7ea387b3d4a71085645a1671d0aea0e298ba1f28db984227dbcc5c9d1e39809041ba0b7
7
+ data.tar.gz: a96e0bcd0089c80c89bed0573ff829d62e727f5b3e4d6de0b87b0a6b3158cb17bb1c5344fbd35bca8a52ced6b9466024365e004dc02fc704005e662a8b34615d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## [0.3.1] - 2022-11-30
4
+
5
+ - Update error handling for more clarity.
6
+
1
7
  ## [0.3.0] - 2022-09-28
2
8
 
3
9
  - Add new requests:
@@ -10,7 +10,7 @@ module KazeClient
10
10
  # Those headers are added on all requests by default
11
11
  DEFAULT_HEADERS = {
12
12
  'Content-Type' => 'application/json',
13
- 'Accept' => 'application/json'
13
+ 'Accept' => 'application/json'
14
14
  }.freeze
15
15
 
16
16
  # @return [String, Symbol] The HTTP verb to use for the request
@@ -64,19 +64,12 @@ module KazeClient
64
64
  # @param response [HTTParty::Response] The response object from HTTParty call
65
65
  # @return [KazeClient::Error::Generic] The adequate error object according to the given response
66
66
  def error_for(response)
67
- # Not found is handled in a specific way since there is no message key and the error has a
68
- # specific format
69
- return KazeClient::Error::NotFound.new if response.code == 404
67
+ error = response.parsed_response['error']
68
+ message = response.parsed_response['message']
70
69
 
71
- # Return the adequate error class for the error code in the response
72
- "KazeClient::Error::#{response.parsed_response['error'].camelize}"
73
- .constantize.new(response.parsed_response['message'])
74
- rescue NameError
75
- # This means no error class exists for the error code in the response, we fallback to a
76
- # generic error
77
- Error::Generic.new(status: response.code,
78
- error: response.parsed_response['error'],
79
- message: response.parsed_response['message'])
70
+ return non_generic_error(error, message, response) if error != 'generic'
71
+
72
+ generic_http_error(error, message, response)
80
73
  end
81
74
 
82
75
  protected
@@ -100,6 +93,8 @@ module KazeClient
100
93
  @body
101
94
  when Hash
102
95
  @body.to_json
96
+ else
97
+ @body.to_s
103
98
  end
104
99
  end
105
100
 
@@ -109,5 +104,30 @@ module KazeClient
109
104
 
110
105
  @query
111
106
  end
107
+
108
+ def non_generic_error(error, message, response)
109
+ # Return the adequate error class for the error code in the response
110
+ "KazeClient::Error::#{error.camelize}".constantize.new(message)
111
+ rescue NameError
112
+ # This means no error class exists for the error code in the response, we fallback to a
113
+ # generic error
114
+ Error::Generic.new(status: response.code, error: error, message: message)
115
+ end
116
+
117
+ def generic_http_error(error, message, response)
118
+ case response.code
119
+ when 401
120
+ KazeClient::Error::Unauthorized.new(message)
121
+ when 403
122
+ KazeClient::Error::Forbidden.new(message)
123
+ when 404
124
+ KazeClient::Error::NotFound.new
125
+ when 500
126
+ KazeClient::Error::InternalServerError.new(message)
127
+ else
128
+ # This means no error class exists for the response code, we fallback to a generic error
129
+ Error::Generic.new(status: response.code, error: error, message: message)
130
+ end
131
+ end
112
132
  end
113
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KazeClient
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaze_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty