ignore errors loading gender/mood data

For example, the site was throwing a 500 error when loading pets
belonging to frozen users. Instead, we'll now rescue that
Neopets::User::AccountDisabledError and ignore it, since it's not
*vital* that we load gender/mood data from this pet; we can still
proceed to load its customization data without it.
This commit is contained in:
Emi Matchu 2012-06-05 13:02:35 -04:00
parent a436362f26
commit b25b6e55b3

View file

@ -69,11 +69,17 @@ class PetState < ActiveRecord::Base
# Find this pet on the owner's userlookup, where we can get both its gender
# and its mood.
begin
user_pet = Neopets::User.new(username).pets.
find { |user_pet| user_pet.name.downcase == pet.name.downcase }
self.female = user_pet.female?
self.mood_id = user_pet.mood.id
self.labeled = true
rescue Neopets::User::Error
# If there's an error loading the userlookup data (e.g. account is
# frozen), no big deal; we just won't label the pet right now. Proceed
# as usual.
end
true
end