Sha256: 394fd99413717439671b3ed6770e99b7a1f1db8bfcfd3c3fa07375dfb459c163

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 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 < Error; 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

7 entries across 7 versions & 1 rubygems

Version Path
bima-shark-sdk-3.1.1 lib/shark/error.rb
bima-shark-sdk-2.5.0 lib/shark/error.rb
bima-shark-sdk-3.1.0 lib/shark/error.rb
bima-shark-sdk-3.0.0 lib/shark/error.rb
bima-shark-sdk-2.4.4 lib/shark/error.rb
bima-shark-sdk-2.4.3 lib/shark/error.rb
bima-shark-sdk-2.4.2 lib/shark/error.rb