lib/esse/errors.rb in esse-0.2.0 vs lib/esse/errors.rb in esse-0.2.2

- old
+ new

@@ -2,10 +2,63 @@ module Esse class Error < StandardError end + # @todo Rename this + module Backend + class ServerError < ::Esse::Error; end + + ES_TRANSPORT_ERRORS = { + 'MultipleChoices' => 'MultipleChoicesError', # 300 + 'MovedPermanently' => 'MovedPermanentlyError', # 301 + 'Found' => 'FoundError', # 302 + 'SeeOther' => 'SeeOtherError', # 303 + 'NotModified' => 'NotModifiedError', # 304 + 'UseProxy' => 'UseProxyError', # 305 + 'TemporaryRedirect' => 'TemporaryRedirectError', # 307 + 'PermanentRedirect' => 'PermanentRedirectError', # 308 + 'BadRequest' => 'BadRequestError', # 400 + 'Unauthorized' => 'UnauthorizedError', # 401 + 'PaymentRequired' => 'PaymentRequiredError', # 402 + 'Forbidden' => 'ForbiddenError', # 403 + 'NotFound' => 'NotFoundError', # 404 + 'MethodNotAllowed' => 'MethodNotAllowedError', # 405 + 'NotAcceptable' => 'NotAcceptableError', # 406 + 'ProxyAuthenticationRequired' => 'ProxyAuthenticationRequiredError', # 407 + 'RequestTimeout' => 'RequestTimeoutError', # 408 + 'Conflict' => 'ConflictError', # 409 + 'Gone' => 'GoneError', # 410 + 'LengthRequired' => 'LengthRequiredError', # 411 + 'PreconditionFailed' => 'PreconditionFailedError', # 412 + 'RequestEntityTooLarge' => 'RequestEntityTooLargeError', # 413 + 'RequestURITooLong' => 'RequestURITooLongError', # 414 + 'UnsupportedMediaType' => 'UnsupportedMediaTypeError', # 415 + 'RequestedRangeNotSatisfiable' => 'RequestedRangeNotSatisfiableError', # 416 + 'ExpectationFailed' => 'ExpectationFailedError', # 417 + 'ImATeapot' => 'ImATeapotError', # 418 + 'TooManyConnectionsFromThisIP' => 'TooManyConnectionsFromThisIPError', # 421 + 'UpgradeRequired' => 'UpgradeRequiredError', # 426 + 'BlockedByWindowsParentalControls' => 'BlockedByWindowsParentalControlsError', # 450 + 'RequestHeaderTooLarge' => 'RequestHeaderTooLargeError', # 494 + 'HTTPToHTTPS' => 'HTTPToHTTPSError', # 497 + 'ClientClosedRequest' => 'ClientClosedRequestError', # 499 + 'InternalServerError' => 'InternalServerError', # 500 + 'NotImplemented' => 'NotImplementedError', # 501 + 'BadGateway' => 'BadGatewayError', # 502 + 'ServiceUnavailable' => 'ServiceUnavailableError', # 503 + 'GatewayTimeout' => 'GatewayTimeoutError', # 504 + 'HTTPVersionNotSupported' => 'HTTPVersionNotSupportedError', # 505 + 'VariantAlsoNegotiates' => 'VariantAlsoNegotiatesError', # 506 + 'NotExtended' => 'NotExtendedError', # 510 + } + + ERRORS = ES_TRANSPORT_ERRORS.each_with_object({}) do |(transport_name, esse_name), memo| + memo[transport_name] = const_set esse_name, Class.new(ServerError) + end + end + module Events class UnregisteredEventError < ::Esse::Error def initialize(object_or_event_id) case object_or_event_id when String, Symbol @@ -40,8 +93,6 @@ end class InvalidOption < Error end end - - # Elasticsearch::Transport::Transport::Errors::NotFound end