Exception: AtlasRb::ReparentError

Inherits:
Error
  • Object
show all
Defined in:
lib/atlas_rb/errors.rb

Overview

Note:

Authorization failures surface as ForbiddenError (HTTP 403), not this — even on a re-parent path.

Raised when Atlas rejects a re-parent (PATCH /<type>/:id/parent) with a structural 422 carrying a machine-readable error discriminator — tombstoned_node, tombstoned_parent, parent_required, invalid_parent_type, cycle, or parent_not_found.

Mirrors StaleResourceError: a narrow translation of one wire signal callers need to discriminate on. Without it the binding's ["collection"] / ["work"] / ["community"] unwrap silently returns nil on a 422, discarding Atlas's error/message and leaving the caller unable to tell an invalid move from a not-found from a forbidden one.

Callers key on #code for specific messaging, falling back to #message:

rescue AtlasRb::ReparentError => e flash.now[:alert] = t("reparent.errors.#ee.code", default: e.message)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code: nil, resource_id: nil) ⇒ ReparentError

Returns a new instance of ReparentError.

Parameters:

  • message (String)

    human-readable rejection description.

  • code (String, nil) (defaults to: nil)

    the envelope's error discriminator.

  • resource_id (String, nil) (defaults to: nil)

    the rejected resource's ID.



69
70
71
72
73
# File 'lib/atlas_rb/errors.rb', line 69

def initialize(message, code: nil, resource_id: nil)
  super(message)
  @code = code
  @resource_id = resource_id
end

Instance Attribute Details

#codeString? (readonly)

Returns the machine-readable error code from the envelope (e.g. "cycle"), suitable for keying an i18n map.

Returns:

  • (String, nil)

    the machine-readable error code from the envelope (e.g. "cycle"), suitable for keying an i18n map.



61
62
63
# File 'lib/atlas_rb/errors.rb', line 61

def code
  @code
end

#resource_idString? (readonly)

Returns the rejected resource's ID, from the envelope.

Returns:

  • (String, nil)

    the rejected resource's ID, from the envelope.



64
65
66
# File 'lib/atlas_rb/errors.rb', line 64

def resource_id
  @resource_id
end