Class: Asimov::ApiV1::NetworkErrorTranslator
- Inherits:
-
Object
- Object
- Asimov::ApiV1::NetworkErrorTranslator
- 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
-
.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.
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. when Net::ReadTimeout raise Asimov::ReadTimeout, orig_error. when Net::WriteTimeout raise Asimov::WriteTimeout, orig_error. when Timeout::Error, Errno::ETIMEDOUT raise Asimov::TimeoutError, orig_error. else # Errno::EINVAL, Errno::ECONNRESET, EOFError, # Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError raise Asimov::NetworkError, orig_error. end end |