Exception: Common::HTTPError

Inherits:
CloudboxError show all
Defined in:
lib/common/cloudbox_exceptions.rb

Overview

Throws a error if an error occurred with a HTTP request.

Direct Known Subclasses

ClientError, ServerError

Constant Summary collapse

@@codes =
{
    400 =>
        {:short => "Bad Request", :long => "The request cannot be fulfilled due to bad syntax."},
    401 =>
        {:short => "Unauthorized", :long => "Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided.[] The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication."},
    402 =>
        {:short => "Payment Required", :long => " Reserved for future use.[] The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. As an example of its use, however, Apple's defunct MobileMe service generated a 40 error if the MobileMe account was delinquent.[citation needed] In addition, YouTube uses this status if a particular IP address has made excessive requests, and requires the person to enter a CAPTCHA."},
    403 =>
        {:short => "Forbidden", :long => "The request was a valid request, but the server is refusing to respond to it.[] Unlike a 401 Unauthorized response, authenticating will make no difference.[] On servers where authentication is required, this commonly means that the provided credentials were successfully authenticated but that the credentials still do not grant the client permission to access the resource (e.g. a recognized user attempting to access restricted content)."},
    404 =>
        {:short => "Not Found", :long => "The requested resource could not be found but may be available again in the future.[] Subsequent requests by the client are permissible."},
    405 =>
        {:short => "Method Not Allowed", :long => "A request was made of a resource using a request method not supported by that resource;[] for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource."},
    406 =>
        {:host => "Not Acceptable", :long => "The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request."},
    407 =>
        {:short => "Proxy Authentication Required", :long => "The client must first authenticate itself with the proxy."},
    408 =>
        {:short => "Request Timeout", :long => "The server timed out waiting for the request. According to W3 HTTP specifications: \"The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.\""},
    409 =>
        {:short => "Conflict", :long => "Indicates that the request could not be processed because of conflict in the request, such as an edit conflict."},
    410 =>
        {:short => "Gone", :long => "Indicates that the resource requested is no longer available and will not be available again. This should be used when a resource has been intentionally removed and the resource should be purged. Upon receiving a 410 status code, the client should not request the resource again in the future. Clients such as search engines should remove the resource from their indices. Most use cases do not require clients and search engines to purge the resource, and a \"404 Not Found\" may be used instead."},
    411 =>
        {:short => "Length Required", :long => "The request did not specify the length of its content, which is required by the requested resource."},
    41 =>
        {:short => "Precondition Failed", :long => "The server does not meet one of the preconditions that the requester put on the request."},
    413 =>
        {:short => "Request Entity Too Large", :long => "The request is larger than the server is willing or able to process."},
    414 =>
        {:short => "Request-URI Too Long", :long => "The URI provided was too long for the server to process."},
    415 =>
        {:short => "Unsupported Media Type", :long => "The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format."},
    416 =>
        {:short => "Requested Range Not Satisfiable", :long => "The client has asked for a portion of the file, but the server cannot supply that portion.[] For example, if the client asked for a part of the file that lies beyond the end of the file."},
    417 =>
        {:short => "Expectation Failed", :long => "The server cannot meet the requirements of the Expect request-header field."},
    418 =>
        {:short => "I'm a teapot (RFC 34)", :long => "This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 34, Hyper Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers."},
    419 =>
        {:short => "Authentication Timeout", :long => "Not a part of the HTTP standard, 419 Authentication Timeout denotes that previously valid authentication has expired. It is used as an alternative to 401 Unauthorized in order to differentiate from otherwise authenticated clients being denied access to specific server resources."},
    40 =>
        {:short => "Enhance Your Calm (Twitter)", :long => "Not part of the HTTP standard, but returned by the Twitter Search and Trends API when the client is being rate limited.[13] Other services may wish to implement the 49 Too Many Requests response code instead."},
    4 =>
        {:short => "Unprocessable Entity (WebDAV; RFC 4918)", :long => "The request was well-formed but was unable to be followed due to semantic errors."},
    43 =>
        {:short => "Locked (WebDAV; RFC 4918)", :long => "The resource that is being accessed is locked."},
    44 =>
        {:short => "Failed Dependency (WebDAV; RFC 4918)", :long => "The request failed due to failure of a previous request (e.g. a PROPPATCH)."},
    44 =>
        {:short => "Method Failure (WebDAV)", :long => "Indicates the method was not executed on a particular resource within its scope because some part of the method's execution failed causing the entire method to be aborted."},
    45 =>
        {:short => "Unordered Collection (Internet draft)", :long => "Defined in drafts of \"WebDAV Advanced Collections Protocol\", but not present in \"Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol\"."},
    46 =>
        {:short => "Upgrade Required (RFC 817)", :long => "The client should switch to a different protocol such as TLS/1.0."},
    48 =>
        {:short => "Precondition Required (RFC 6585)", :long => "The origin server requires the request to be conditional. Intended to prevent \"the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.\""},
    49 =>
        {:short => "Too Many Requests (RFC 6585)", :long => "The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes."},
    431 =>
        {:short => "Request Header Fields Too Large (RFC 6585)", :long => "The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large."},
    444 =>
        {:short => "No Response (Nginx)", :long => "Used in Nginx logs to indicate that the server has returned no information to the client and closed the connection (useful as a deterrent for malware)."},
    449 =>
        {:short => "Retry With (Microsoft)", :long => "A Microsoft extension. The request should be retried after performing the appropriate action."},
    450 =>
        {:short => "Blocked by Windows Parental Controls (Microsoft)", :long => "A Microsoft extension. This error is given when Windows Parental Controls are turned on and are blocking access to the given webpage."},
    451 =>
        {:short => "Unavailable For Legal Reasons (Internet draft)", :long => "Defined in the internet draft \"A New HTTP Status Code for Legally-restricted Resources\". Intended to be used when resource access is denied for legal reasons, e.g. censorship or government-mandated blocked access. A reference to the 1953 dystopian novel Fahrenheit 451, where books are outlawed."},
    451 =>
        {:short => "Redirect (Microsoft)", :long => "Used in Exchange ActiveSync if there either is a more efficient server to use or the server can't access the users' mailbox."},
    494 =>
        {:short => "Request Header Too Large (Nginx)", :long => "Nginx internal code similar to 413 but it was introduced earlier."},
    495 =>
        {:short => "Cert Error (Nginx)", :long => "Nginx internal code used when SSL client certificate error occurred to distinguish it from 4XX in a log and an error page redirection."},
    496 =>
        {:short => "No Cert (Nginx)", :long => "Nginx internal code used when client didn't provide certificate to distinguish it from 4XX in a log and an error page redirection."},
    497 =>
        {:short => "HTTP to HTTPS (Nginx)", :long => "Nginx internal code used for the plain HTTP requests that are sent to HTTPS port to distinguish it from 4XX in a log and an error page redirection."},
    499 =>
        {:short => "Client Closed Request (Nginx)", :long => "Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing its request, making server unable to send a status code back."},
    500 =>
        {:short => "Internal Server Error", :long => "A generic error message, given when no more specific message is suitable."},
    501 =>
        {:short => "Not Implemented", :long => "The server either does not recognize the request method, or it lacks the ability to fulfill the request."},
    502 =>
        {:short => "Bad Gateway", :long => "The server was acting as a gateway or proxy and received an invalid response from the upstream server."},
    503 =>
        {:short => "Service Unavailable", :long => "The server is currently unavailable (because it is overloaded or down for maintenance).[2] Generally, this is a temporary state."},
    504 =>
        {:short => "Gateway Timeout", :long => "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server."},
    505 =>
        {:short => "HTTP Version Not Supported", :long => "The server does not support the HTTP protocol version used in the request."},
    506 =>
        {:short => "Variant Also Negotiates (RFC 2295)", :long => "Transparent content negotiation for the request results in a circular reference."},
    507 =>
        {:short => "Insufficient Storage (WebDAV; RFC 4918)", :long => "The server is unable to store the representation needed to complete the request."},
    508 =>
        {:short => "Loop Detected (WebDAV; RFC 5842)", :long => "The server detected an infinite loop while processing the request (sent in lieu of 208)."},
    509 =>
        {:short => "Bandwidth Limit Exceeded (Apache bw/limited extension)", :long => "This status code, while used by many servers, is not specified in any RFCs."},
    510 =>
        {:short => "Not Extended (RFC 2774)", :long => "Further extensions to the request are required for the server to fulfil it."},
    511 =>
        {:short => "Network Authentication Required (RFC 6585)", :long => "The client needs to authenticate to gain network access. Intended for use by intercepting proxies used to control access to the network (e.g. \"captive portals\" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot)."},
    598 =>
        {:short => "Network read timeout error (Unknown)", :long => "This status code is not specified in any RFCs, but is used by Microsoft HTTP proxies to signal a network read timeout behind the proxy to a client in front of the proxy.[citation needed]"},
    599 =>
        {:short => "Network connect timeout error (Unknown)", :long => "This status code is not specified in any RFCs, but is used by Microsoft HTTP proxies to signal a network connect timeout behind the proxy to a client in front of the proxy.[citation needed]"}
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code, body = nil) ⇒ HTTPError

Note:

Overrides default constructor by passing CustomCommandOption to super().

Default constructor of the class.



480
481
482
483
484
# File 'lib/common/cloudbox_exceptions.rb', line 480

def initialize(message, code, body=nil)
  super(message)
  @code = code
  @body = body
end

Class Method Details

.getConsistentError(message, code, body) ⇒ Object

Get the consistent error message of the request



467
468
469
470
471
472
473
474
475
476
# File 'lib/common/cloudbox_exceptions.rb', line 467

def self.getConsistentError(message, code, body)
  code = code.to_i
  if code > 399 && code < 500
    return ClientError.new(message, code, body)
  elsif code > 499 && code < 600
    return ServerError.new(message, code, body)
  else
    return HTTPError.new(message, code, body)
  end
end

Instance Method Details

#bodyObject

Get the body of the request



492
493
494
# File 'lib/common/cloudbox_exceptions.rb', line 492

def body()
  return @body
end

#codeObject

Get the code status of the request



487
488
489
# File 'lib/common/cloudbox_exceptions.rb', line 487

def code()
  return @code
end

#longHttpMessageObject

Get the long HTTP message of the request



503
504
505
506
# File 'lib/common/cloudbox_exceptions.rb', line 503

def longHttpMessage()
  return "" if @@codes[@code].nil?
  return @@codes[@code][:long]
end

#shortHttpMessageObject

Get the short HTTP message of the request



497
498
499
500
# File 'lib/common/cloudbox_exceptions.rb', line 497

def shortHttpMessage()
  return "" if @@codes[@code].nil?
  return @@codes[@code][:short]
end