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
# File 'lib/supabase/postgrest/errors.rb', line 13

def initialize(error = {})
  @raw = error || {}
  @message = @raw["message"] || @raw[:message]
  @code = @raw["code"] || @raw[:code]
  @hint = @raw["hint"] || @raw[:hint]
  @details = @raw["details"] || @raw[:details]
  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

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
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



33
34
35
# File 'lib/supabase/postgrest/errors.rb', line 33

def json
  @raw
end

#to_sObject



22
23
24
25
26
27
28
29
30
# File 'lib/supabase/postgrest/errors.rb', line 22

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