Class: X::MissingResource
- Inherits:
-
Objects::Error
- Object
- Error
- Objects::Error
- X::MissingResource
- Defined in:
- x-objects/lib/x/objects/errors.rb
Overview
Raised when a resource that was asked for by identifier or name does not exist
The API answers a lookup of a resource that is not there with 200 OK and no data, so this is not the NotFound of a 404 response, which an endpoint that is not there raises, and which holds the response that named it.
It is raised as well when a request that creates a resource, such as X::Post.create, succeeds without returning it, as X::User.current! raises it when users/me returns no user, holding the problems the response reported.
Instance Attribute Summary collapse
-
#problems ⇒ Array<Problem>
readonly
The problems the API reported about the resource.
Instance Method Summary collapse
-
#initialize(message = nil, problems: []) ⇒ MissingResource
constructor
Initialize the error, adding the detail of the first problem to the message.
Constructor Details
#initialize(message = nil, problems: []) ⇒ MissingResource
Initialize the error, adding the detail of the first problem to the message
42 43 44 45 46 |
# File 'x-objects/lib/x/objects/errors.rb', line 42 def initialize( = nil, problems: []) explanation = problems.first&.then { |problem| problem.detail || problem.title } super(([, explanation].compact.join(": ") if || explanation)) @problems = problems.dup.freeze end |
Instance Attribute Details
#problems ⇒ Array<Problem> (readonly)
The problems the API reported about the resource
32 33 34 |
# File 'x-objects/lib/x/objects/errors.rb', line 32 def problems @problems end |