Sha256: 0dcb161d9a9073054344ca3d1d8923045f6ea96499e3c1c3e2a8b81a7d64369f

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module SolanaRuby
  class BaseClient
    require 'active_support/core_ext/string/inflections'
    
    private

    def handle_http_response(response)
      body = JSON.parse(response.body)
      # puts "body:==== #{body}"
      if response.is_a?(Net::HTTPSuccess)
        if body['error']
          raise "API Error: #{body['error']['code']} - #{body['error']['message']}"
        else
          return body
        end
      else
        raise "HTTP Error: #{response.code} - #{body['error']['message']}"
      end
    rescue JSON::ParserError
      raise "Invalid JSON response: #{response.body}"
    end

    def handle_error(error)
      case error
      when Timeout::Error
        raise SolanaError.new('Request timed out')
      when SocketError
        raise SolanaError.new('Failed to connect to the server')
      else
        raise SolanaError.new("An unexpected error occurred: #{error.message}")
      end
    end
  end

  class SolanaError < StandardError
    def initialize(message)
      super(message)
    end

    def backtrace
      []
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solana-ruby-web3js-1.0.1.beta4 lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.1.beta3 lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.1.beta2 lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.1.beta1 lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.0.beta lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.1 lib/solana_ruby/base_client.rb
solana-ruby-web3js-1.0.0 lib/solana_ruby/base_client.rb