Skip to content

Conversation

p8
Copy link
Contributor

@p8 p8 commented Jul 30, 2024

RemoteResource.find_by raises a RemoteResource::HTTPNotFound error if the resource can't be found. This is unexpected as ActiveRecord::Base.find_by doesn't raise when the record can't be found.
ActiveRecord::Base.find_by! does raise an error.

Current implementation:

ActiveRecord::Base RemoteResource
find_by return nil raises
find_by! raises not implemented

Having a RemoteResource.find_by method that doesn't raise can be useful, as we currently rescue the RemoteResource::HTTPNotFound error instead in a lot of places. To make RemoteResource behave more like ActiveRecord and have separate finder methods that raise or return nil we can add a .find_by! method that raises and let .find_by return nil instead:

ActiveRecord::Base RemoteResource
find_by return nil return nil
find_by! raises raises

As .find_by is used a lot, we deprecate it first in this PR. In version 2.0 we can make .find_by return nil instead.
This PR:

ActiveRecord::Base RemoteResource
find_by return nil raises and shows a deprecation warning
find_by! raises raises

@p8 p8 force-pushed the find_by_bang branch 2 times, most recently from 94c2a3c to 327bf7b Compare August 8, 2024 14:41
`.find_by` raises a `RemoteResource::HTTPNotFound` error if the resource
can't be found. This is unexpected as `ActiveRecord::Base.find_by`
doesn't raise when the record can't be found.
`ActiveRecord::Base.find_by!` does raise an error.

To make RemoteResource behave more like ActiveRecord and have separate
finder methods that raise or return `nil` we can add a `.find_by!`
method that raises and let `.find_by` return `nil` instead.

As `.find_by` is used a lot, we deprecate it first.
In version 2.0 we can make `.find_by` return `nil` instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant