Module: Strata::CLI::API::ConnectionErrorHandler

Included in:
Client, Generators::Project
Defined in:
lib/strata/cli/api/connection_error_handler.rb

Overview

Handles connection errors and provides user-friendly error messages

Instance Method Summary collapse

Instance Method Details

#with_connection_error_handling(server_url) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/strata/cli/api/connection_error_handler.rb', line 10

def with_connection_error_handling(server_url)
  yield
rescue Faraday::ConnectionFailed => e
  handle_connection_error(server_url, e)
rescue Faraday::TimeoutError => e
  handle_connection_error(server_url, e, timeout: true)
rescue Faraday::Error => e
  # Check if it's a connection-related error
  if e.message.include?("Connection refused") ||
      e.message.include?("Failed to open TCP connection") ||
      e.message.include?("getaddrinfo") ||
      e.message.include?("No route to host")
    handle_connection_error(server_url, e)
  else
    raise Strata::CommandError, "Network error: #{e.message}"
  end
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EHOSTUNREACH => e
  handle_connection_error(server_url, e)
end