Class: DeepL::Utils::ExceptionBuilder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ExceptionBuilder

Returns a new instance of ExceptionBuilder.



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

def initialize(response)
  @response = response
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/deepl/utils/exception_builder.rb', line 9

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/deepl/utils/exception_builder.rb', line 9

def response
  @response
end

Class Method Details

.error_class_from_response_code(code) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deepl/utils/exception_builder.rb', line 11

def self.error_class_from_response_code(code) # rubocop:disable Metrics/CyclomaticComplexity
  case code
  when 400 then Exceptions::BadRequest
  when 401, 403 then Exceptions::AuthorizationFailed
  when 404 then Exceptions::NotFound
  when 413 then Exceptions::RequestEntityTooLarge
  when 429 then Exceptions::LimitExceeded
  when 456 then Exceptions::QuotaExceeded
  when 500..599 then Exceptions::ServerError
  else Exceptions::RequestError
  end
end

Instance Method Details

#buildObject



28
29
30
31
# File 'lib/deepl/utils/exception_builder.rb', line 28

def build
  error_class = self.class.error_class_from_response_code(response.code.to_i)
  error_class.new(response)
end