Exception: Excon::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/excon/error.rb

Overview

Excon exception classes

Defined Under Namespace

Classes: Accepted, BadGateway, BadRequest, Certificate, Client, Conflict, Continue, Created, ExpectationFailed, Forbidden, Found, GatewayTimeout, Gone, HTTPStatus, Informational, InternalServerError, InvalidHeaderKey, InvalidHeaderValue, InvalidStub, LengthRequired, MethodNotAllowed, MovedPermanently, MultipleChoices, NoContent, NonAuthoritativeInformation, NotAcceptable, NotFound, NotImplemented, NotModified, OK, PartialContent, PaymentRequired, PreconditionFailed, ProxyAuthenticationRequired, ProxyConnectionError, ProxyParse, Redirection, RequestEntityTooLarge, RequestTimeout, RequestURITooLong, RequestedRangeNotSatisfiable, ResetContent, ResponseParse, SeeOther, Server, ServiceUnavailable, Socket, StubNotFound, Success, SwitchingProtocols, TemporaryRedirect, Timeout, TooManyRedirects, TooManyRequests, Unauthorized, UnprocessableEntity, UnsupportedMediaType, UseProxy, Warning

Class Method Summary collapse

Class Method Details

.status_error(request, response) ⇒ Object

Messages for nicer exceptions, from rfc2616



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/excon/error.rb', line 174

def self.status_error(request, response)
  error_class, error_message = status_errors[response[:status]]
  if error_class.nil?
    default_class = Excon::Error.const_get(@default_status_error)
    error_class, error_message = [default_class, 'Unknown']
  end
  message = StringIO.new
  str = "Expected(#{request[:expects].inspect}) <=>" +
        " Actual(#{response[:status]} #{error_message})"
  message.puts(str)
  if request[:debug_request]
    message.puts('excon.error.request')
    Excon::PrettyPrinter.pp(message, request)
  end

  if request[:debug_response]
    message.puts('excon.error.response')
    Excon::PrettyPrinter.pp(message, response.data)
  end
  message.rewind
  error_class.new(message.read, request, response)
end

.status_errorsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/excon/error.rb', line 127

def self.status_errors
  @status_errors ||= {
    100 => [Excon::Error::Continue, 'Continue'],
    101 => [Excon::Error::SwitchingProtocols, 'Switching Protocols'],
    200 => [Excon::Error::OK, 'OK'],
    201 => [Excon::Error::Created, 'Created'],
    202 => [Excon::Error::Accepted, 'Accepted'],
    203 => [Excon::Error::NonAuthoritativeInformation, 'Non-Authoritative Information'],
    204 => [Excon::Error::NoContent, 'No Content'],
    205 => [Excon::Error::ResetContent, 'Reset Content'],
    206 => [Excon::Error::PartialContent, 'Partial Content'],
    300 => [Excon::Error::MultipleChoices, 'Multiple Choices'],
    301 => [Excon::Error::MovedPermanently, 'Moved Permanently'],
    302 => [Excon::Error::Found, 'Found'],
    303 => [Excon::Error::SeeOther, 'See Other'],
    304 => [Excon::Error::NotModified, 'Not Modified'],
    305 => [Excon::Error::UseProxy, 'Use Proxy'],
    307 => [Excon::Error::TemporaryRedirect, 'Temporary Redirect'],
    400 => [Excon::Error::BadRequest, 'Bad Request'],
    401 => [Excon::Error::Unauthorized, 'Unauthorized'],
    402 => [Excon::Error::PaymentRequired, 'Payment Required'],
    403 => [Excon::Error::Forbidden, 'Forbidden'],
    404 => [Excon::Error::NotFound, 'Not Found'],
    405 => [Excon::Error::MethodNotAllowed, 'Method Not Allowed'],
    406 => [Excon::Error::NotAcceptable, 'Not Acceptable'],
    407 => [Excon::Error::ProxyAuthenticationRequired, 'Proxy Authentication Required'],
    408 => [Excon::Error::RequestTimeout, 'Request Timeout'],
    409 => [Excon::Error::Conflict, 'Conflict'],
    410 => [Excon::Error::Gone, 'Gone'],
    411 => [Excon::Error::LengthRequired, 'Length Required'],
    412 => [Excon::Error::PreconditionFailed, 'Precondition Failed'],
    413 => [Excon::Error::RequestEntityTooLarge, 'Request Entity Too Large'],
    414 => [Excon::Error::RequestURITooLong, 'Request-URI Too Long'],
    415 => [Excon::Error::UnsupportedMediaType, 'Unsupported Media Type'],
    416 => [Excon::Error::RequestedRangeNotSatisfiable, 'Request Range Not Satisfiable'],
    417 => [Excon::Error::ExpectationFailed, 'Expectation Failed'],
    422 => [Excon::Error::UnprocessableEntity, 'Unprocessable Entity'],
    429 => [Excon::Error::TooManyRequests, 'Too Many Requests'],
    500 => [Excon::Error::InternalServerError, 'InternalServerError'],
    501 => [Excon::Error::NotImplemented, 'Not Implemented'],
    502 => [Excon::Error::BadGateway, 'Bad Gateway'],
    503 => [Excon::Error::ServiceUnavailable, 'Service Unavailable'],
    504 => [Excon::Error::GatewayTimeout, 'Gateway Timeout']
  }
end