Class: DeepL::Utils::ExceptionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/deepl/utils/exception_builder.rb

Constant Summary collapse

ERROR_CODE_CLASS_MAP =
{
  '400' => Exceptions::BadRequest,
  '401' => Exceptions::AuthorizationFailed,
  '403' => Exceptions::AuthorizationFailed,
  '404' => Exceptions::NotFound,
  '413' => Exceptions::RequestEntityTooLarge,
  '429' => Exceptions::LimitExceeded,
  '456' => Exceptions::QuotaExceeded
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ ExceptionBuilder

Returns a new instance of ExceptionBuilder.



18
19
20
21
# File 'lib/deepl/utils/exception_builder.rb', line 18

def initialize(request, response)
  @request = request
  @response = response
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/deepl/utils/exception_builder.rb', line 6

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/deepl/utils/exception_builder.rb', line 6

def response
  @response
end

Instance Method Details

#buildObject



23
24
25
26
# File 'lib/deepl/utils/exception_builder.rb', line 23

def build
  error_class = ERROR_CODE_CLASS_MAP[response.code.to_s] || Exceptions::RequestError
  error_class.new(request, response)
end