mint_http 0.1.12 → 1.0.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: d96c48d259517f6bb8012cf6e00600db417b48ebdb570bab246e4727f24707b7
4
- data.tar.gz: a2b117a6ab762c733625d647aff7de509cc8a13a0679754dad16ed856290207d
3
+ metadata.gz: e9e732a985585fb708b2ed2c520fe271224c121cae660000c59e948fa341e21c
4
+ data.tar.gz: 00fc67f3613bac4feff07b5e659dc7b6712e5efa75a378a63692bc22534b1b54
5
5
  SHA512:
6
- metadata.gz: 1757883fb698f942f30f5f352229eee819733cde43961b9e82a35631d8bbc11e8cd2b690be4159194368200df3d521eba3b5ea847dadc5ddae953b270852219c
7
- data.tar.gz: dad7ef02f77b7e0a8341216d6cc95f62a409a076c24e0a3bd6840e071208be9e1ceee52376aa6388d3bd4530ce4520659838b5b5acef590425a4974c59b0c444
6
+ metadata.gz: 4c36fa3817748e4ec1fc4b1c5ff3e640a5bd39a21dec8c2322d92557a24d9384ebac9f7cd7713f37637c58def3af9534d9111af3f384a546ef1ea0d2147b5d8e
7
+ data.tar.gz: 21376671680cbb833dd922e5f6cdbd4fd6cfd87c6ba036eb0701fd89df0cccc52e428981dd28c869793586e1d8d308b0fc3e32e6d9660c23ac2e1312dd8daad2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.12] - 2024-11-05
4
+
5
+ - Improve error handling by introducing new error base class that makes it easy for users to catch and deal with errors.
6
+ - Add more HTTP error classes.
7
+
8
+
9
+ ## [0.1.12] - 2024-10-13
10
+
11
+ - Fix Logging when server returns a UTF-8 response with invalid encoding set in header
12
+
13
+
3
14
  ## [0.1.0] - 2023-07-03
4
15
 
5
16
  - Initial release
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in mint_http.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
-
10
- gem "minitest", "~> 5.0"
8
+ gem 'rake', '~> 13.0'
9
+ gem 'minitest', '~> 5.0'
10
+ gem 'resolv-replace'
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mint_http (0.1.8)
4
+ mint_http (0.1.12)
5
5
  base64
6
6
  json
7
7
  net-http
8
8
  openssl
9
+ resolv
9
10
  uri
10
11
 
11
12
  GEM
@@ -18,6 +19,9 @@ GEM
18
19
  uri
19
20
  openssl (3.2.0)
20
21
  rake (13.0.6)
22
+ resolv (0.4.0)
23
+ resolv-replace (0.1.1)
24
+ resolv
21
25
  uri (0.13.0)
22
26
 
23
27
  PLATFORMS
@@ -27,6 +31,7 @@ DEPENDENCIES
27
31
  minitest (~> 5.0)
28
32
  mint_http!
29
33
  rake (~> 13.0)
34
+ resolv-replace
30
35
 
31
36
  BUNDLED WITH
32
- 2.3.16
37
+ 2.5.6
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MintHttp
4
+ class Error < StandardError; end
5
+
6
+ # Errno::EHOSTUNREACH: The network host is unreachable, often due to network configuration issues or connectivity problems.
7
+ # ENETUNREACH
8
+ class ConnectionError < Error; end
9
+
10
+ # Errno::ECONNREFUSED: The connection was refused by the remote server, often because the port is closed or the server is not running.
11
+ class ConnectionRefusedError < ConnectionError; end
12
+
13
+ # Errno::ECONNRESET: The connection was reset by the peer (the other end of the connection), typically due to abrupt disconnection.
14
+ class ConnectionResetError < ConnectionError; end
15
+
16
+ # Errno::ECONNABORTED: The connection was aborted, often due to the network or the other side abruptly closing the connection.
17
+ class ConnectionAbortedError < ConnectionError; end
18
+
19
+ # IOError
20
+ # EOFError: Raised when an end-of-file condition is reached, often indicating that the connection was closed by the peer during reading.
21
+ # Errno::EPIPE: Writing to a closed socket results in this error, indicating a "broken pipe."
22
+ # Errno::EIO: Input/output error, typically indicating an issue with reading or writing to the socket due to a system-level error.
23
+ class ConnectionIoError < ConnectionError; end
24
+
25
+ # DNS Errors
26
+ # SocketError: getaddrinfo
27
+ # Resolv::ResolvError
28
+ # Resolv::ResolvTimeout
29
+ class NameResolutionError < ConnectionError; end
30
+
31
+ # SSL Error
32
+ # OpenSSL::SSL::SSLError
33
+ class ConnectionSslError < ConnectionError; end
34
+
35
+ class TimeoutError < Error; end
36
+ class ReadTimeoutError < TimeoutError; end
37
+ class WriteTimeoutError < TimeoutError; end
38
+ class OpenTimeoutError < TimeoutError; end
39
+
40
+ class ResponseError < Error
41
+ # @return [HTTP::Response]
42
+ attr_reader :response
43
+
44
+ def initialize(msg, response)
45
+ super(msg)
46
+ @response = response
47
+ end
48
+
49
+ def to_s
50
+ response.inspect
51
+ end
52
+ end
53
+
54
+ class ServerError < ResponseError; end
55
+ class BadGatewayError < ServerError; end
56
+ class ServiceUnavailableError < ServerError; end
57
+ class GatewayTimeoutError < ServerError; end
58
+
59
+
60
+ class ClientError < ResponseError; end
61
+ class NotFoundError < ClientError; end
62
+ class AuthenticationError < ClientError; end
63
+ class AuthorizationError < ClientError; end
64
+ end
@@ -5,6 +5,7 @@ require 'net/http'
5
5
  require 'uri'
6
6
  require 'openssl'
7
7
  require 'json'
8
+ require 'resolv'
8
9
 
9
10
  module MintHttp
10
11
  class Request
@@ -281,6 +282,7 @@ module MintHttp
281
282
  logger.log_end
282
283
  logger.log_error(error)
283
284
  logger.write_log
285
+
284
286
  raise error
285
287
  end
286
288
 
@@ -293,6 +295,33 @@ module MintHttp
293
295
  logger.write_log
294
296
 
295
297
  response
298
+
299
+ rescue SocketError => e
300
+ if e.message.include?('getaddrinfo') || e.cause.is_a?(Resolv::ResolvError) || e.cause.is_a?(Resolv::ResolvTimeout)
301
+ raise NameResolutionError, e.message
302
+ else
303
+ raise ConnectionIoError, e.message
304
+ end
305
+
306
+ rescue Net::OpenTimeout => e
307
+ raise OpenTimeoutError, e.message
308
+ rescue Net::WriteTimeout => e
309
+ raise WriteTimeoutError, e.message
310
+ rescue Net::ReadTimeout => e
311
+ raise ReadTimeoutError, e.message
312
+
313
+ rescue Errno::ECONNREFUSED => e
314
+ raise ConnectionRefusedError, e.message
315
+ rescue Errno::ECONNRESET => e
316
+ raise ConnectionResetError, e.message
317
+
318
+ rescue IOError, EOFError, Errno::EPIPE, Errno::EIO => e
319
+ raise ConnectionIoError, e.message
320
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH => e
321
+ raise ConnectionError, e.message
322
+
323
+ rescue OpenSSL::SSL::SSLError => e
324
+ raise ConnectionSslError, e.message
296
325
  end
297
326
 
298
327
  private
@@ -85,6 +85,12 @@ module MintHttp
85
85
  raise AuthorizationError.new('Forbidden', self)
86
86
  when 404
87
87
  raise NotFoundError.new('Not Found', self)
88
+ when 502
89
+ raise BadGatewayError.new('Bad Gateway', self)
90
+ when 503
91
+ raise ServiceUnavailableError.new('Service Unavailable', self)
92
+ when 504
93
+ raise GatewayTimeoutError.new('Gateway Timeout', self)
88
94
  when 400..499
89
95
  raise ClientError.new('Client Error', self)
90
96
  when 500..599
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MintHttp
4
- VERSION = "0.1.12"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/mint_http.rb CHANGED
@@ -7,12 +7,7 @@ require_relative 'mint_http/config'
7
7
  require_relative 'mint_http/pool_entry'
8
8
  require_relative 'mint_http/pool'
9
9
  require_relative 'mint_http/headers'
10
- require_relative 'mint_http/errors/response_error'
11
- require_relative 'mint_http/errors/server_error'
12
- require_relative 'mint_http/errors/client_error'
13
- require_relative 'mint_http/errors/authorization_error'
14
- require_relative 'mint_http/errors/authentication_error'
15
- require_relative 'mint_http/errors/not_found_error'
10
+ require_relative 'mint_http/errors'
16
11
  require_relative 'mint_http/net_http_factory'
17
12
  require_relative 'mint_http/request_logger'
18
13
  require_relative 'mint_http/response'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mint_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Alhoshaiyan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-13 00:00:00.000000000 Z
11
+ date: 2024-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: resolv
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Like a mint breeze, MintHttp allows you to write simple HTTP requests
84
98
  while giving you the full power of Net::HTTP.
85
99
  email:
@@ -96,12 +110,7 @@ files:
96
110
  - Rakefile
97
111
  - lib/mint_http.rb
98
112
  - lib/mint_http/config.rb
99
- - lib/mint_http/errors/authentication_error.rb
100
- - lib/mint_http/errors/authorization_error.rb
101
- - lib/mint_http/errors/client_error.rb
102
- - lib/mint_http/errors/not_found_error.rb
103
- - lib/mint_http/errors/response_error.rb
104
- - lib/mint_http/errors/server_error.rb
113
+ - lib/mint_http/errors.rb
105
114
  - lib/mint_http/headers.rb
106
115
  - lib/mint_http/net_http_factory.rb
107
116
  - lib/mint_http/pool.rb
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::AuthenticationError < MintHttp::ClientError
4
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::AuthorizationError < MintHttp::ClientError
4
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::ClientError < MintHttp::ResponseError
4
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::NotFoundError < MintHttp::ClientError
4
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::ResponseError < StandardError
4
- # @return [HTTP::Response]
5
- attr_reader :response
6
-
7
- def initialize(msg, response)
8
- super(msg)
9
- @response = response
10
- end
11
-
12
- def to_s
13
- response.inspect
14
- end
15
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MintHttp::ServerError < MintHttp::ResponseError
4
- end