Class: DeepL::Utils::ExceptionBuilder
- Inherits:
-
Object
- Object
- DeepL::Utils::ExceptionBuilder
- Defined in:
- lib/deepl/utils/exception_builder.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.error_class_from_response_code(code) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(response) ⇒ ExceptionBuilder
constructor
A new instance of ExceptionBuilder.
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
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/deepl/utils/exception_builder.rb', line 9 def request @request end |
#response ⇒ Object (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
#build ⇒ Object
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 |