Exception: DeepL::Exceptions::RequestError

Inherits:
Error
  • Object
show all
Defined in:
lib/deepl/exceptions/request_error.rb

Instance Attribute Summary collapse

Attributes inherited from Error

#http_status_code

Instance Method Summary collapse

Methods inherited from Error

#should_retry?

Constructor Details

#initialize(response, request = nil) ⇒ RequestError

Returns a new instance of RequestError.



11
12
13
14
15
16
# File 'lib/deepl/exceptions/request_error.rb', line 11

def initialize(response, request = nil)
  super()
  @response = response
  @request = request
  @http_status_code = response.code.to_i if response.respond_to?(:code)
end

Instance Attribute Details

#request ⇒ Object (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/deepl/exceptions/request_error.rb', line 9

def request
  @request
end

#response ⇒ Object (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/deepl/exceptions/request_error.rb', line 9

def response
  @response
end

Instance Method Details

#to_s ⇒ Object



18
19
20
21
22
# File 'lib/deepl/exceptions/request_error.rb', line 18

def to_s
  message = body_message
  status = "HTTP status #{http_status_code}"
  message ? "Request failed with #{status}: #{message}" : "Request failed with #{status}."
end