Sha256: 350d303a43b5527d495080ff9f9aa60b3c82f8ccf4890db2e41294c2fe495b25

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

module RightApi

  class ApiError < RuntimeError
    # Create a new ApiError. This accepts a parameter glob because this type is aliased to
    # a removed exception type that took only one initializer argument: the response object.
    # This type prefers two arguments: the request and response objects. If you pass only one
    # argument, it is taken to be the response.
    def initialize(*args)
      case args.size
      when 1
        # Compatible with RightApi::Exceptions::ApiException (from 1.5.9 of the gem)
        @request, @response = nil, args[0]
      when 2
        # Normal/preferred format
        @request, @response = args[0], args[1]
      else
        raise ArgumentError, "wrong number of arguments (#{args.size} for 1 or 2)"
      end

      super(
        prefix +
        "HTTP Code: #{@response.code.to_s}, " +
        "Response body: #{@response.body}")
    end

    def prefix

      'Error: '
    end
  end

  class UnknownRouteError < ApiError

    def prefix

      'Unknown action or route. '
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
right_api_client-1.5.25 lib/right_api_client/errors.rb
right_api_client-1.5.24 lib/right_api_client/errors.rb
right_api_client-1.5.23 lib/right_api_client/errors.rb
right_api_client-1.5.22 lib/right_api_client/errors.rb
right_api_client-1.5.21 lib/right_api_client/errors.rb
right_api_client-1.5.19 lib/right_api_client/errors.rb
right_api_client-1.5.18 lib/right_api_client/errors.rb
right_api_client-1.5.17 lib/right_api_client/errors.rb
right_api_client-1.5.16 lib/right_api_client/errors.rb
right_api_client-1.5.15 lib/right_api_client/errors.rb
right_api_client-1.5.14 lib/right_api_client/errors.rb