Exception: Supabase::Postgrest::Errors::APIError

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

Overview

Raised when the PostgREST server returns a non-success status. Mirrors supabase-py’s APIError — exposes :message, :code, :hint, :details plus the raw error hash via #raw.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = {}) ⇒ APIError

Returns a new instance of APIError.

Parameters:

  • error (Hash) (defaults to: {})

    parsed JSON body from a PostgREST error response



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

def initialize(error = {})
  if error.is_a?(Hash)
    @raw = error
    @message = @raw["message"] || @raw[:message]
    @code = @raw["code"] || @raw[:code]
    @hint = @raw["hint"] || @raw[:hint]
    @details = @raw["details"] || @raw[:details]
  elsif error.nil?
    @raw = {}
  else
    @raw = error
    @message = "PostgREST returned non-hash error: #{error.inspect}"
  end
  super(to_s)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/supabase/postgrest/errors.rb', line 10

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



10
11
12
# File 'lib/supabase/postgrest/errors.rb', line 10

def details
  @details
end

#hintObject (readonly)

Returns the value of attribute hint.



10
11
12
# File 'lib/supabase/postgrest/errors.rb', line 10

def hint
  @hint
end

#rawObject (readonly)

Returns the value of attribute raw.



10
11
12
# File 'lib/supabase/postgrest/errors.rb', line 10

def raw
  @raw
end

Instance Method Details

#jsonHash

Returns the raw error payload as received.

Returns:

  • (Hash)

    the raw error payload as received



45
46
47
# File 'lib/supabase/postgrest/errors.rb', line 45

def json
  @raw
end

#messageObject

Override StandardError#message so the field-level value is non-nil.



30
31
32
# File 'lib/supabase/postgrest/errors.rb', line 30

def message
  @message.to_s
end

#to_sObject



34
35
36
37
38
39
40
41
42
# File 'lib/supabase/postgrest/errors.rb', line 34

def to_s
  parts = []
  parts << "Error #{@code}:" if @code
  parts << "\nMessage: #{@message}" if @message
  parts << "\nHint: #{@hint}" if @hint
  parts << "\nDetails: #{@details}" if @details
  result = parts.join
  result.empty? ? "Empty error" : result
end