forked from OpenNeo/impress
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:
parent
a436362f26
commit
b25b6e55b3
1 changed files with 11 additions and 5 deletions
|
@ -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.
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue