Sha256: f35747ad0933d6518d14e54953642dffe7ecf5ade71553500259a5c2746857b4

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 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

1 entries across 1 versions & 1 rubygems

Version Path
smartdc-1.3.0 lib/smartdc/error.rb