From c93895b2f772d92c9498862d9653f263e69835d5 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 1 Feb 2024 07:21:47 -0800 Subject: [PATCH] Fix mistake in pet loading error handling Oops, warning isn't enough, we also need to stop, right lol! I moved this into a method, so we could `return` out of there. --- app/models/pet_type.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 37a3a820..720577a0 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -25,6 +25,8 @@ class PetType < ApplicationRecord where(color_id: color.id, species_id: species.id) } + before_save :load_image_hash + def self.special_color_or_basic(special_color) color_ids = special_color ? [special_color.id] : Color.basic.select([:id]).map(&:id) where(color_id: color_ids) @@ -121,7 +123,7 @@ class PetType < ApplicationRecord pet_state end - before_save do + def load_image_hash if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME cpn_uri = URI.parse sprintf(IMAGE_CPN_FORMAT, CGI.escape(@origin_pet.name)) begin @@ -136,8 +138,10 @@ class PetType < ApplicationRecord res.error! rescue Exception => e Rails.logger.warn "Error loading CPN image at #{cpn_uri}: #{e.message}" + return else Rails.logger.warn "Error loading CPN image at #{cpn_uri}. Response: #{res.inspect}" + return end end new_url = res['location']