Sha256: 2ee84c3c4ba4e7e1fd461997783c977d9b2c952941ef4271db8df10cbbbb740a

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true
module Roqua
  module Healthy
    class Error < StandardError; end
    class ConnectionError < Error; end
    class NACK < Error; end

    class IllegalMirthResponse < ConnectionError; end
    class Timeout < ConnectionError; end
    class HostUnreachable < ConnectionError; end
    class ConnectionRefused < ConnectionError; end

    class UnknownFailure < Error; end
    class PatientIdNotInRemote < Error; end
    class PatientNotFound < Error; end
    class AuthenticationFailure < Error; end

    module MirthErrors
      class WrongPatient < Error; end
    end

    def self.convert_generic_errors_to_healthy_errors
      yield
    rescue RestClient::Exceptions::ReadTimeout, RestClient::Exceptions::OpenTimeout => error
      raise ::Roqua::Healthy::Timeout, error.message
    rescue ::Timeout::Error => error
      raise ::Roqua::Healthy::Timeout, error.message
    rescue Errno::ETIMEDOUT => error
      raise ::Roqua::Healthy::Timeout, error.message
    rescue Errno::EHOSTUNREACH => error
      raise ::Roqua::Healthy::HostUnreachable, error.message
    rescue Errno::ECONNREFUSED => error
      raise ::Roqua::Healthy::ConnectionRefused, error.message
    end

    ERRORS = {
      'Timeout waiting for ACK' =>
        ::Roqua::Healthy::Timeout,
      "Unable to connect to destination\tSocketTimeoutException\tconnect timed out" =>
        ::Roqua::Healthy::Timeout,
      'ERROR: Timeout waiting for response' =>
        ::Roqua::Healthy::Timeout,
      'ERROR: SocketTimeoutException: connect timed out' =>
        ::Roqua::Healthy::Timeout,
      "Unable to connect to destination\tConnectException\tConnection refused" =>
        ::Roqua::Healthy::ConnectionRefused,
      'ERROR: ConnectException: Connection refused' =>
        ::Roqua::Healthy::ConnectionRefused
    }.freeze
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roqua-healthy-1.5.2 lib/roqua/healthy/errors.rb
roqua-healthy-1.5.1 lib/roqua/healthy/errors.rb