Exception: Putio::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Putio::Error
- Defined in:
- lib/putio-ruby/error.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #build_error_message ⇒ Object
- #error_message ⇒ Object
- #error_type ⇒ Object
-
#initialize(env = nil) ⇒ Error
constructor
A new instance of Error.
- #response_body ⇒ Object
- #response_error ⇒ Object
- #response_headers ⇒ Object
- #response_status ⇒ Object
Constructor Details
#initialize(env = nil) ⇒ Error
Returns a new instance of Error.
14 15 16 17 |
# File 'lib/putio-ruby/error.rb', line 14 def initialize(env=nil) @env = env super() end |
Class Method Details
.from_env(env) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/putio-ruby/error.rb', line 3 def self.from_env(env) status = env.status if klass = case status when 400..499 then Putio::BadRequest when 500..599 then Putio::ServerError end klass.new(env) end end |
Instance Method Details
#build_error_message ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/putio-ruby/error.rb', line 29 def return nil if @env.nil? = "#{@env.method.to_s.upcase} " << "#{@env.status} - #{@env.url}\n" << "#{response_error}" unless response_error.nil? end |
#error_message ⇒ Object
54 55 56 |
# File 'lib/putio-ruby/error.rb', line 54 def @env.body["error_message"] end |
#error_type ⇒ Object
50 51 52 |
# File 'lib/putio-ruby/error.rb', line 50 def error_type @env.body["error_type"] end |
#response_body ⇒ Object
46 47 48 |
# File 'lib/putio-ruby/error.rb', line 46 def response_body @env.body end |
#response_error ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/putio-ruby/error.rb', line 19 def response_error if response_body && error_type && "#{error_type}: #{}" elsif response_body && else response_body end end |
#response_headers ⇒ Object
38 39 40 |
# File 'lib/putio-ruby/error.rb', line 38 def response_headers @env.response_headers end |
#response_status ⇒ Object
42 43 44 |
# File 'lib/putio-ruby/error.rb', line 42 def response_status @env.status end |