Sha256: afae6309984ce1e742743fcda6df6438ab22b21334121ac323cb8b1be30b9229

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Shark
  class Error < StandardError; end

  class ApiError < Error
    attr_reader :code, :env

    def initialize(code, env)
      @code = code
      @env = env
    end

    def body
      env[:body]
    end

    def url
      env[:url]
    end

    def message
      body.to_s
    end
  end

  class ConnectionError < ApiError
    def initialize(env)
      @env = env
    end
  end

  class ClientError < ApiError; end

  class AccessDenied < ClientError; end

  class NotAuthorized < ClientError; end

  class ResourceConflict < ClientError; end

  class ResourceNotFound < ClientError
    def message
      "Couldn't find resource at: #{url}"
    end
  end

  class UnprocessableEntity < ClientError
    def errors
      body['errors'] || {}
    end

    def message
      errors.to_json
    end
  end

  class ServerError < ApiError; end

  class UnexpectedStatus < ServerError
    def message
      "Unexpected response status: #{code} from: #{url}"
    end
  end

  #
  # Other errors
  #
  class ActionNotSupportedError < Error; end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bima-shark-sdk-2.4.1 lib/shark/error.rb
bima-shark-sdk-2.4.0 lib/shark/error.rb
bima-shark-sdk-2.3.1 lib/shark/error.rb
bima-shark-sdk-2.3.0 lib/shark/error.rb