Sha256: 652591fe6e3e66eb0044f52944900c90e83cd8e9bd95f31cf70777ba5007e299

Contents?: true

Size: 784 Bytes

Versions: 4

Compression:

Stored size: 784 Bytes

Contents

module Xdelivery

  module Exceptions

    EXCEPTIONS_MAP = {}
  end

  class Client
    class UnknownResponse < StandardError; end

    EXPECTED_STATUSES = {
      200 => 'Ok' ,
      401 => 'Unauthorized'
    }

    EXCEPTION_STATUSES = {
      404 => 'Not Found',
      500 => 'Internal Server Error',
      502 => 'Bad Gateway',
      503 => 'Service Unavailable',
      504 => 'Gateway Timeout',
    }

    EXCEPTION_STATUSES.each_pair do |code, message|
      klass = Class.new(StandardError) do
        send(:define_method, :message) { "#{code}, #{message}" }
      end
      const_name = message.delete(',\.\-\'\"').split(' ').map(&:capitalize).join
      klass_constant = const_set(const_name, klass)
      Exceptions::EXCEPTIONS_MAP[code] = klass_constant
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xdelivery-2.0.3 lib/xdelivery/exceptions.rb
xdelivery-2.0.1 lib/xdelivery/exceptions.rb
xdelivery-2.0.0 lib/xdelivery/exceptions.rb
xdelivery-1.0.2 lib/xdelivery/exceptions.rb