Skip to content

Commit

Permalink
Merge pull request #59 from github/ac-error-codes-to-syscall-errors
Browse files Browse the repository at this point in the history
Ensure syscall error subclasses have an error_code attribute
  • Loading branch information
adrianna-chang-shopify authored Mar 16, 2023
2 parents 80c1a55 + 3d09114 commit bd92053
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions contrib/ruby/lib/trilogy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Trilogy
# Trilogy::Error is the base error type. All errors raised by Trilogy
# should be descendants of Trilogy::Error
module Error
attr_reader :error_code
end

# Trilogy::ConnectionError is the base error type for all potentially transient
Expand All @@ -15,8 +16,6 @@ module ConnectionError
class BaseError < StandardError
include Error

attr_reader :error_code

def initialize(error_message = nil, error_code = nil)
message = error_code ? "#{error_code}: #{error_message}" : error_message
super(message)
Expand All @@ -43,8 +42,6 @@ class CastError < ClientError
class TimeoutError < Errno::ETIMEDOUT
include ConnectionError

attr_reader :error_code

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
Expand All @@ -53,10 +50,20 @@ def initialize(error_message = nil, error_code = nil)

class ConnectionRefusedError < Errno::ECONNREFUSED
include ConnectionError

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
end
end

class ConnectionResetError < Errno::ECONNRESET
include ConnectionError

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
end
end

# DatabaseError was replaced by ProtocolError, but we'll keep it around as an
Expand Down

0 comments on commit bd92053

Please sign in to comment.