Exception: DHC::Error
- Inherits:
-
StandardError
- Object
- StandardError
- DHC::Error
- Includes:
- FixInvalidEncodingConcern
- Defined in:
- lib/dhc/error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_message ⇒ Object
Returns the value of attribute _message.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, response) ⇒ Error
constructor
A new instance of Error.
- #to_s ⇒ Object
Constructor Details
#initialize(message, response) ⇒ Error
56 57 58 59 60 |
# File 'lib/dhc/error.rb', line 56 def initialize(, response) super() self. = self.response = response end |
Instance Attribute Details
#_message ⇒ Object
Returns the value of attribute _message.
6 7 8 |
# File 'lib/dhc/error.rb', line 6 def end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/dhc/error.rb', line 6 def response @response end |
Class Method Details
.dup ⇒ Object
52 53 54 |
# File 'lib/dhc/error.rb', line 52 def self.dup self end |
.find(response) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/dhc/error.rb', line 44 def self.find(response) return DHC::Timeout if response.timeout? status_code = response.code.to_s[0..2].to_i error = map[status_code] error ||= DHC::UnknownError error end |
.map ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dhc/error.rb', line 8 def self.map { 400 => DHC::BadRequest, 401 => DHC::, 402 => DHC::PaymentRequired, 403 => DHC::Forbidden, 404 => DHC::NotFound, 405 => DHC::MethodNotAllowed, 406 => DHC::NotAcceptable, 407 => DHC::ProxyAuthenticationRequired, 408 => DHC::RequestTimeout, 409 => DHC::Conflict, 410 => DHC::Gone, 411 => DHC::LengthRequired, 412 => DHC::PreconditionFailed, 413 => DHC::RequestEntityTooLarge, 414 => DHC::RequestUriToLong, 415 => DHC::UnsupportedMediaType, 416 => DHC::RequestedRangeNotSatisfiable, 417 => DHC::ExpectationFailed, 422 => DHC::UnprocessableEntity, 423 => DHC::Locked, 424 => DHC::FailedDependency, 426 => DHC::UpgradeRequired, 500 => DHC::InternalServerError, 501 => DHC::NotImplemented, 502 => DHC::BadGateway, 503 => DHC::ServiceUnavailable, 504 => DHC::GatewayTimeout, 505 => DHC::HttpVersionNotSupported, 507 => DHC::InsufficientStorage, 510 => DHC::NotExtended } end |
.to_a ⇒ Object
62 63 64 |
# File 'lib/dhc/error.rb', line 62 def self.to_a [self] end |
Instance Method Details
#to_s ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dhc/error.rb', line 66 def to_s return response.to_s unless response.is_a?(DHC::Response) request = response.request return unless request.is_a?(DHC::Request) debug = [] debug << [request.method, request.url].map { |str| self.class.fix_invalid_encoding(str) }.join(' ') debug << "Response Code: #{response.code} (#{response.options[:return_code]})" debug << response.body debug << debug.map { |str| self.class.fix_invalid_encoding(str) }.join("\n") end |