Exception: AtlasRb::ResourceError

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

Overview

Note:

Authorization failures on the narrow re-parent / linked-member / Compilation write paths surface as ForbiddenError via Middleware::RaiseOnResourceError; this is the catch-all for the read path, which that middleware intentionally does not cover.

Raised by the typed single-resource readers (AtlasRb::Resource.find and the Work / Collection / Community / FileSet / Person / Compilation / Blob / Delegate overrides) when Atlas answers the GET with a non-2xx that is not a 404 — i.e. an error envelope ({ "error" => ... }, status 400/401/403/422) on what the caller treated as a plain read.

Before this existed, find unwrapped the success body by a fixed key (["work"], ["collection"], …); on an error envelope that key is absent, so find returned nil and silently discarded Atlas's status and message. The caller then dereferenced the nil far from the cause (the canonical symptom: undefined method 'tombstoned' for nil). This error keeps the failure at the boundary, carrying the status and body so the real cause (e.g. … → 401: {"error":"invalid bearer token"}) is attributable everywhere find is used.

A genuine 404 is not this — it stays a clean nil return, since "not found" is a normal find outcome callers already nil-check.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response: nil) ⇒ ResourceError

Returns a new instance of ResourceError.

Parameters:

  • message (String)

    human-readable failure description.

  • response (Faraday::Response, nil) (defaults to: nil)

    the originating response; its status and body are captured for callers that rescue this.



239
240
241
242
243
244
# File 'lib/atlas_rb/errors.rb', line 239

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

Instance Attribute Details

#bodyString? (readonly)

Returns Atlas's raw response body (the error envelope).

Returns:

  • (String, nil)

    Atlas's raw response body (the error envelope).



234
235
236
# File 'lib/atlas_rb/errors.rb', line 234

def body
  @body
end

#responseFaraday::Response? (readonly)

Returns the originating response, when available.

Returns:

  • (Faraday::Response, nil)

    the originating response, when available.



228
229
230
# File 'lib/atlas_rb/errors.rb', line 228

def response
  @response
end

#statusInteger? (readonly)

Returns Atlas's HTTP status.

Returns:

  • (Integer, nil)

    Atlas's HTTP status.



231
232
233
# File 'lib/atlas_rb/errors.rb', line 231

def status
  @status
end