Sha256: d10e3dc67d7f26603244be2d48ea1f87a45c02610bb73d9847f5959dfc20d382

Contents?: true

Size: 1.72 KB

Versions: 29

Compression:

Stored size: 1.72 KB

Contents

=begin
#Fastly API

#Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://developer.fastly.com/reference/api/) 

The version of the OpenAPI document: 1.0.0
Contact: oss@fastly.com

=end

module Fastly
  class ApiError < StandardError
    attr_reader :code, :response_headers, :response_body

    # Usage examples:
    #   ApiError.new
    #   ApiError.new("message")
    #   ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
    #   ApiError.new(:code => 404, :message => "Not Found")
    def initialize(arg = nil)
      if arg.is_a? Hash
        if arg.key?(:message) || arg.key?('message')
          super(arg[:message] || arg['message'])
        else
          super arg
        end

        arg.each do |k, v|
          instance_variable_set "@#{k}", v
        end
      else
        super arg
      end
    end

    # Override to_s to display a friendly error message
    def to_s
      message
    end

    def message
      if @message.nil?
        msg = "Error message: the server returns an error"
      else
        msg = @message
      end

      msg += "\nHTTP status code: #{code}" if code
      msg += "\nResponse headers: #{response_headers}" if response_headers
      msg += "\nResponse body: #{response_body}" if response_body

      msg
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
fastly-8.2.0 lib/fastly/api_error.rb
fastly-8.1.0 lib/fastly/api_error.rb
fastly-8.0.1 lib/fastly/api_error.rb
fastly-8.0.0 lib/fastly/api_error.rb
fastly-7.2.2 lib/fastly/api_error.rb
fastly-7.2.1 lib/fastly/api_error.rb
fastly-7.2.0 lib/fastly/api_error.rb
fastly-7.1.1 lib/fastly/api_error.rb
fastly-7.1.0 lib/fastly/api_error.rb
fastly-7.0.0 lib/fastly/api_error.rb
fastly-6.0.2 lib/fastly/api_error.rb
fastly-6.0.1 lib/fastly/api_error.rb
fastly-6.0.0 lib/fastly/api_error.rb
fastly-5.3.1 lib/fastly/api_error.rb
fastly-5.3.0 lib/fastly/api_error.rb
fastly-5.2.2 lib/fastly/api_error.rb
fastly-5.2.1 lib/fastly/api_error.rb
fastly-5.2.0 lib/fastly/api_error.rb
fastly-5.1.1 lib/fastly/api_error.rb
fastly-5.1.0 lib/fastly/api_error.rb