Sha256: 442683cb724de5f80903847d36d2111c63c675b7024ab9c2968a3d7e82ebe1dc

Contents?: true

Size: 1.98 KB

Versions: 6

Compression:

Stored size: 1.98 KB

Contents

class OpenpayExceptionFactory

  def OpenpayExceptionFactory::create(exception)

    LOG.warn("An exception has been raised (original exception class: #{exception.class})")

    case exception

      #resource not found
      #malformed jason, invalid data, invalid request
      when RestClient::BadRequest, RestClient::ResourceNotFound,
          RestClient::Conflict, RestClient::PaymentRequired,
          RestClient::UnprocessableEntity

        oe=OpenpayTransactionException.new exception.http_body
        LOG.warn "-OpenpayTransactionException: #{exception.http_body}"
        @errors=true
        raise oe

      #connection, timeouts, network related errors
      when Errno::EADDRINUSE, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError
        #since this exceptions are not based on the rest api exceptions
        #we do not have the json message so we just build the exception
        #with the original exception message set in e.description and e.message
        oe=OpenpayConnectionException.new(exception.message,false)
        LOG.warn exception.message
        @errors=true
        raise oe
      #badgateway-connection error, invalid credentials
      when  RestClient::BadGateway, RestClient::Unauthorized, RestClient::RequestTimeout
            LOG.warn exception
            if exception.http_body
              oe=OpenpayConnectionException.new exception.http_body
            else
              oe=OpenpayConnectionException.new(exception.message, false)
            end
            @errors=true
            raise oe

      when  RestClient::Exception , RestClient::InternalServerError
            LOG.warn exception
            if exception.http_body
              oe=OpenpayException.new exception.http_body
            else
              oe=OpenpayException.new(exception.message, false)
            end
            @errors=true
            raise oe
      else
        #We won't hide unknown exceptions , those should be raised
        LOG.warn exception.message
        raise exception
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openpay-2.0.1 lib/openpay/errors/openpay_exception_factory.rb
openpay-2.0.0 lib/openpay/errors/openpay_exception_factory.rb
openpay-2.0.0b lib/openpay/errors/openpay_exception_factory.rb
openpay-1.0.10 lib/openpay/errors/openpay_exception_factory.rb
openpay-1.0.8 lib/openpay/errors/openpay_exception_factory.rb
openpay-1.0.7 lib/openpay/errors/openpay_exception_factory.rb