From dfb3aeb9dec63937289a581673622415eb72473a Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 27 Jul 2015 19:36:13 -0400 Subject: [PATCH] 404 on bad page type name --- app/controllers/neopets_page_import_tasks_controller.rb | 1 + app/models/neopets_page.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/neopets_page_import_tasks_controller.rb b/app/controllers/neopets_page_import_tasks_controller.rb index 653f2c17..e432193a 100644 --- a/app/controllers/neopets_page_import_tasks_controller.rb +++ b/app/controllers/neopets_page_import_tasks_controller.rb @@ -6,6 +6,7 @@ class NeopetsPageImportTasksController < ApplicationController before_filter :require_source, only: [:create] rescue_from NeopetsPage::ParseError, with: :on_parse_error + rescue_from NeopetsPage::TypeNotFound, with: :not_found def create neopets_page = NeopetsPage.new(params[:page_type], params[:expected_index].to_i, params[:neopets_page][:source]) diff --git a/app/models/neopets_page.rb b/app/models/neopets_page.rb index 2f7dc90f..52d63310 100644 --- a/app/models/neopets_page.rb +++ b/app/models/neopets_page.rb @@ -10,7 +10,11 @@ class NeopetsPage def initialize(type_key, expected_index, source) - @type = TYPES.fetch(type_key) + begin + @type = TYPES.fetch(type_key) + rescue KeyError + raise TypeNotFound, type_key + end @expected_index = expected_index @source = source end @@ -354,5 +358,6 @@ class NeopetsPage end - class ParseError < RuntimeError;end + class ParseError < RuntimeError; end + class TypeNotFound < RuntimeError; end end