Class: X::MissingResource
- Inherits:
-
Resources::Error
- Object
- Error
- Resources::Error
- X::MissingResource
- Defined in:
- x-resources/lib/x/resources/errors.rb
Overview
Raised when a resource that was asked for by identifier or name does not exist
A lookup of one resource that is not there raises it whether the API answers 200 OK with no data or a 404 that reports the resource as not found, so code that rescues it need not know which. It is not the NotFound of x-core, which holds the response, and which every other 404 raises, such as one from a client pointed at the wrong host or API version; the NotFound of a 404 that reports the resource is the cause of this.
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
44 45 46 47 48 |
# File 'x-resources/lib/x/resources/errors.rb', line 44 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
34 35 36 |
# File 'x-resources/lib/x/resources/errors.rb', line 34 def problems @problems end |