Exception: Uploadcare::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/uploadcare/errors/errors.rb

Direct Known Subclasses

RequestError, ServerError

Defined Under Namespace

Classes: RequestError, ServerError

Class Method Summary collapse

Class Method Details

.define_error(code, klass, message) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'lib/uploadcare/errors/errors.rb', line 4

def self.define_error code, klass, message
  class_eval <<-EOD
    class #{klass} < self
      def initialize( message = nil )
        super( message || "HTTP #{code} - #{message}" )
      end
    end
  EOD
end

.errorsObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/uploadcare/errors/errors.rb', line 14

def self.errors
  @errors ||= {
    400 => Uploadcare::Error::RequestError::BadRequest,
    401 => Uploadcare::Error::RequestError::Unauthorized,
    403 => Uploadcare::Error::RequestError::Forbidden,
    404 => Uploadcare::Error::RequestError::NotFound,
    406 => Uploadcare::Error::RequestError::NotAcceptable,
    408 => Uploadcare::Error::RequestError::RequestTimeout,
    422 => Uploadcare::Error::RequestError::UnprocessableEntity,
    429 => Uploadcare::Error::RequestError::TooManyRequests,
    500 => Uploadcare::Error::ServerError::InternalServerError,
    502 => Uploadcare::Error::ServerError::BadGateway,
    503 => Uploadcare::Error::ServerError::ServiceUnavailable,
    504 => Uploadcare::Error::ServerError::GatewayTimeout,
  }
end