Sha256: f270f8707b630f6e3911e48da11586d6d9f42eecb086450d4ff59e66ef70b48a

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

=begin
#Svix API

#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 1.1.1

Generated by: https://openapi-generator.tech
Generator version: 7.9.0

=end

module Svix
  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
        @message = 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

9 entries across 9 versions & 1 rubygems

Version Path
svix-1.56.0 lib/svix/api_error.rb
svix-1.45.1 lib/svix/api_error.rb
svix-1.45.0 lib/svix/api_error.rb
svix-1.44.0 lib/svix/api_error.rb
svix-1.43.0 lib/svix/api_error.rb
svix-1.42.0 lib/svix/api_error.rb
svix-1.41.0 lib/svix/api_error.rb
svix-1.40.0 lib/svix/api_error.rb
svix-1.39.0 lib/svix/api_error.rb