Exception: Sink::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/sink/error.rb,
lib/sink/error.rb

Constant Summary collapse

STATUS_ERRORS =
{
  400 => ValidationError,
  401 => Unauthorized,
  403 => Forbidden,
  404 => NotFound,
  409 => Conflict,
  422 => ValidationError,
  423 => StorageNotReady,
  429 => RateLimited
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, status: nil, body: nil) ⇒ Error

Returns a new instance of Error.



12
13
14
15
16
# File 'lib/sink/error.rb', line 12

def initialize(message = nil, status: nil, body: nil)
  @status = status
  @body = body
  super(message)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/sink/error.rb', line 5

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/sink/error.rb', line 5

def status
  @status
end

Class Method Details

.for(status:, message:, body: nil) ⇒ Object



7
8
9
10
# File 'lib/sink/error.rb', line 7

def self.for(status:, message:, body: nil)
  klass = STATUS_ERRORS[status] || (status.to_i >= 500 ? ServerError : self)
  klass.new(message, status: status, body: body)
end

Instance Method Details

#dataObject



18
# File 'lib/sink/error.rb', line 18

def data = body.is_a?(Hash) ? body["data"] : nil