diff --git a/app/controllers/pets_controller.rb b/app/controllers/pets_controller.rb index e6d4081e..8dbaf3e4 100644 --- a/app/controllers/pets_controller.rb +++ b/app/controllers/pets_controller.rb @@ -1,13 +1,13 @@ class PetsController < ApplicationController - rescue_from Pet::PetNotFound, with: :pet_not_found - rescue_from Pet::DownloadError, with: :pet_download_error + rescue_from Neopets::CustomPets::PetNotFound, with: :pet_not_found + rescue_from Neopets::CustomPets::DownloadError, with: :pet_download_error rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format def load # Uncomment this to temporarily disable modeling for most users. # return modeling_disabled unless user_signed_in? && current_user.admin? - raise Pet::PetNotFound unless params[:name] + raise Neopets::CustomPets::PetNotFound unless params[:name] @pet = Pet.load(params[:name]) points = contribute(current_user, @pet) diff --git a/app/models/pet.rb b/app/models/pet.rb index d0d6ceed..c716f273 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -114,5 +114,7 @@ class Pet < ApplicationRecord pet.load!(**options) pet end + + class UnexpectedDataFormat < RuntimeError;end end diff --git a/app/services/neopets/custom_pets.rb b/app/services/neopets/custom_pets.rb index b7d468da..9e38b545 100644 --- a/app/services/neopets/custom_pets.rb +++ b/app/services/neopets/custom_pets.rb @@ -45,7 +45,7 @@ module Neopets::CustomPets private - # Send an AMFPHP request, re-raising errors as `Pet::DownloadError`. + # Send an AMFPHP request, re-raising errors as `DownloadError`. # Return the response body as a `HashWithIndifferentAccess`. def send_amfphp_request(request, timeout: 10) begin @@ -61,4 +61,7 @@ module Neopets::CustomPets HashWithIndifferentAccess.new(response_data) end end + + class PetNotFound < RuntimeError;end + class DownloadError < RuntimeError;end end