-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.rb
More file actions
158 lines (144 loc) · 4.08 KB
/
error.rb
File metadata and controls
158 lines (144 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# frozen_string_literal: true
module Wreq
# Network connection errors
# Connection to the server failed.
#
# Raised when the client cannot establish a connection to the server.
#
# @example
# begin
# client.get("http://localhost:9999")
# rescue Wreq::ConnectionError => e
# puts "Connection failed: #{e.message}"
# retry_with_backoff
# end
unless const_defined?(:ConnectionError)
class ConnectionError < StandardError; end
end
# Connection was reset by the server.
#
# Raised when the server closes the connection unexpectedly.
#
# @example
# rescue Wreq::ConnectionResetError => e
# puts "Connection reset: #{e.message}"
# end
unless const_defined?(:ConnectionResetError)
class ConnectionResetError < StandardError; end
end
# TLS/SSL error occurred.
#
# Raised when there's an error with TLS/SSL, such as certificate
# verification failure or protocol mismatch.
#
# @example
# begin
# client.get("https://self-signed.badssl.com")
# rescue Wreq::TlsError => e
# puts "TLS error: #{e.message}"
# end
unless const_defined?(:TlsError)
class TlsError < StandardError; end
end
# HTTP protocol and request/response errors
# Request failed.
#
# Generic error for request failures that don't fit other categories.
#
# @example
# rescue Wreq::RequestError => e
# puts "Request failed: #{e.message}"
# end
unless const_defined?(:RequestError)
class RequestError < StandardError; end
end
# HTTP status code indicates an error.
#
# Raised when the server returns an error status code (4xx or 5xx).
#
# @example
# begin
# response = client.get("https://httpbin.org/status/404")
# rescue Wreq::StatusError => e
# puts "HTTP error: #{e.message}"
# # e.response contains the full response
# end
unless const_defined?(:StatusError)
class StatusError < StandardError; end
end
# Redirect handling failed.
#
# Raised when too many redirects occur or redirect logic fails.
#
# @example
# begin
# client = Wreq::Client.new(max_redirects: 3)
# client.get("https://httpbin.org/redirect/10")
# rescue Wreq::RedirectError => e
# puts "Too many redirects: #{e.message}"
# end
unless const_defined?(:RedirectError)
class RedirectError < StandardError; end
end
# Request timed out.
#
# Raised when the request exceeds the configured timeout.
#
# @example
# begin
# client = Wreq::Client.new(timeout: 5)
# client.get("https://httpbin.org/delay/10")
# rescue Wreq::TimeoutError => e
# puts "Request timed out: #{e.message}"
# retry_with_longer_timeout
# end
unless const_defined?(:TimeoutError)
class TimeoutError < StandardError; end
end
# Data processing and encoding errors
# Response body processing failed.
#
# Raised when there's an error reading or processing the response body.
#
# @example
# rescue Wreq::BodyError => e
# puts "Body error: #{e.message}"
# end
unless const_defined?(:BodyError)
class BodyError < StandardError; end
end
# Decoding response failed.
#
# Raised when response content cannot be decoded (e.g., invalid UTF-8,
# malformed JSON, corrupted compression).
#
# @example
# begin
# response = client.get("https://example.com/invalid-utf8")
# response.text # May raise DecodingError
# rescue Wreq::DecodingError => e
# puts "Decoding error: #{e.message}"
# # Fall back to binary data
# data = response.body
# end
unless const_defined?(:DecodingError)
class DecodingError < StandardError; end
end
# Configuration and builder errors
# Client configuration is invalid.
#
# Raised when the client is configured with invalid options.
#
# @example
# begin
# client = Wreq::Client.new(
# proxy: "invalid://proxy",
# timeout: -1
# )
# rescue Wreq::BuilderError => e
# puts "Invalid configuration: #{e.message}"
# end
unless const_defined?(:BuilderError)
class BuilderError < StandardError; end
end
end