Class: Asimov::ApiV1::NetworkErrorTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/asimov/api_v1/network_error_translator.rb

Overview

Translates errors that are generated by Net::HTTP into Asimov::NetworkErrors or a specific subclass to allow better handling by clients of the library.

Class Method Summary collapse

Class Method Details

.translate(orig_error) ⇒ Object

Translates an original error generated by the underlying network stack to an Asimov::NetworkError or a specific subclass, preserving the message from the original error.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asimov/api_v1/network_error_translator.rb', line 15

def self.translate(orig_error)
  case orig_error
  when Net::OpenTimeout
    raise Asimov::OpenTimeout, orig_error.message
  when Net::ReadTimeout
    raise Asimov::ReadTimeout, orig_error.message
  when Net::WriteTimeout
    raise Asimov::WriteTimeout, orig_error.message
  when Timeout::Error, Errno::ETIMEDOUT
    raise Asimov::TimeoutError, orig_error.message
  else
    # Errno::EINVAL, Errno::ECONNRESET, EOFError,
    # Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
    raise Asimov::NetworkError, orig_error.message
  end
end