Sha256: 6e5423d397984fc26cc475f101fded0e7a8cdea7399e73b6a5f62a9c41ba201c

Contents?: true

Size: 997 Bytes

Versions: 5

Compression:

Stored size: 997 Bytes

Contents

module Smartdc
  class Error < StandardError
    attr_reader :response

    def initialize(response)
      @response = response
      begin
        body = JSON.parse(response[:body])
        if body['error_message']
          super(body['error_message'])
        else
          super(response[:body])
        end
      rescue
        super(response[:body])
      end
    end

    def response_status
      response[:status]
    end
  end

  class Error::BadRequest < Smartdc::Error; end
  class Error::Unauthorized < Smartdc::Error; end
  class Error::Forbidden < Smartdc::Error; end
  class Error::NotFound < Smartdc::Error; end
  class Error::MethodNotAllowed < Smartdc::Error; end
  class Error::NotAcceptable < Smartdc::Error; end
  class Error::Conflict < Smartdc::Error; end
  class Error::InternalServerError < Smartdc::Error; end
  class Error::NotImplemented < Smartdc::Error; end
  class Error::BadGateway < Smartdc::Error; end
  class Error::ServiceUnavailable < Smartdc::Error; end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
smartdc-1.2.2 lib/smartdc/error.rb
smartdc-1.2.1 lib/smartdc/error.rb
smartdc-1.1.1 lib/smartdc/error.rb
smartdc-1.0.1 lib/smartdc/error.rb
smartdc-0.4.0 lib/smartdc/error.rb