From 465ef06be4920b2fef8258b76317c6e84144a729 Mon Sep 17 00:00:00 2001 From: Tommy Palmer Date: Wed, 11 Jun 2014 16:18:17 +0100 Subject: [PATCH] 404 if the Repo can't find a document With the introduction of a Repo for fetching documents, the Repo would throw an error if params[:section_id] didn't match a placeholder file instead of allowing the controller to respond with a 404. This commit checks for the existence of a file first, which if false allows the controller to respond with a 404. --- app/repositories/manuals_repository.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/repositories/manuals_repository.rb b/app/repositories/manuals_repository.rb index 0956810d..509a972c 100644 --- a/app/repositories/manuals_repository.rb +++ b/app/repositories/manuals_repository.rb @@ -16,7 +16,9 @@ def fetch_from_file(manual_id, section_id) section_id ||= 'index' path = "public/#{manual_id}/#{section_id}.json" - build_ostruct(JSON.parse(File.open(path).read)) + if File.exists?(path) + build_ostruct(JSON.parse(File.open(path).read)) + end end def fetch_from_api(manual_id, section_id)