File tree Expand file tree Collapse file tree 2 files changed +1
-19
lines changed
Expand file tree Collapse file tree 2 files changed +1
-19
lines changed Original file line number Diff line number Diff line change 4444stack_exchange = StackExchange .new (" stackoverflow" , 1 )
4545puts stack_exchange.questions
4646puts stack_exchange.users
47-
48- # Error Handling with :foul option
49- # HTTParty provides a convenient way to handle common network errors using the :foul option
50- begin
51- HTTParty .get(' https://api.example.com/users' , foul: true )
52- rescue HTTParty ::Foul => e
53- puts " Network error occurred: #{ e.message } "
54- puts " Original error: #{ e.original_error.class } "
55- end
56-
57- # The :foul option wraps common network errors into HTTParty::Foul:
58- # - Errno::ECONNREFUSED (Connection refused)
59- # - Errno::ECONNRESET (Connection reset)
60- # - Errno::EHOSTUNREACH (Host unreachable)
61- # - EOFError (End of file error)
62- # - Net::ReadTimeout (Read timeout)
63- # - SocketError (DNS resolution errors)
64- # - OpenSSL::SSL::SSLError (SSL certificate issues)
6547```
6648
6749See the [ examples directory] ( http://github.com/jnunemaker/httparty/tree/main/examples ) for even more goodies.
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class APIClient
77 def self . fetch_user ( id )
88 begin
99 get ( "/users/#{ id } " , foul : true )
10- rescue HTTParty ::Foul => e
10+ rescue HTTParty ::NetworkError => e
1111 handle_network_error ( e )
1212 rescue HTTParty ::ResponseError => e
1313 handle_api_error ( e )
You can’t perform that action at this time.
0 commit comments