From b25b6e55b36fe973e1df97c0b6f3517ca6656295 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 5 Jun 2012 13:02:35 -0400 Subject: [PATCH] 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. --- app/models/pet_state.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 93eea67e..8044bf87 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -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