We have over 8k in AUS and 2.5 in UK events of this type:
https://app.bugsnag.com/yaycode/openfoodnetwork-uk/errors/5dd433e559edc60018caf959?filters[event.since][0]=30d&filters[error.status][0]=open

Users type the correct shop URL but the shop name refers to a non existing shop or an inactive shop. The user sees a snail (and a bugsnag event is created).
This damages reputation and seo.
The user can be redirected to the list of shops. Ideally an flash message is displayed "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."
Snail.
Inexistent enterprise:
https://openfoodnetwork.org.uk/theres-no-place-like-home/shop
Inactive/not visible shop:
https://openfoodnetwork.org.uk/pomeroys-rare-breeds-robyns-famhouse/shop
Create a shop and set it so that it's not visible in the frontoffice then visit it's shopfront using it's permalink.
None.
We are talking about hundreds of (potential) customers seeing the OFN snail page.
bug-s3: a feature is broken but there is a workaround
We just need a redirect to the shop list page and flash message. A few lines of code on the controller.
Here's the other related issue: https://github.com/openfoodfoundation/openfoodnetwork/issues/3765
Can I work on this one or leave it for new developers?
Hey @jeduardo824 you are very welcome to pick this one up 馃檪
Great. I should send a PR by the weekend.
Hey guys, I was working on a solution, but I don't know if the path I'm following is the best.
Basically, since .find throws an exception when the record is not found, I'm doing this:
rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_shops
[...]
private
def redirect_to_shops
flash[:error] = #I18n with message
redirect_to shops_path
end
[...]
What do you guys think about that?
I'm also can use a begin rescue block. The real doubt is about the exception rescue. 馃槃
yeah, I think that's it :+1: But I'd always go for a local rescue.
in this case I'd remove the distributor assignment form reset_order (remove the first line of the method) and add a method like this:
def distributor
@distributor ||= Enterprise.is_distributor.find_by_permalink(params[:id]) ||
Enterprise.is_distributor.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:error] = #I18n with message
redirect_to shops_path
end
The problem with this approach is when the method reset_distributor(order, distributor) is called. I'm getting a type mismatch error.
I'd suggest you create a draft PR and paste the error. Someone will be able to help you.
btw, looking at the code again, I realized most of this order reset logic here should be moved to the reset_order_service.
Most helpful comment
Can I work on this one or leave it for new developers?