From: Tara L Andrews <tla@mit.edu>
Date: Tue, 11 Sep 2012 08:02:25 +0000 (+0200)
Subject: better error handling of missing / forbidden traditions
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f7b9631ddcaa9468c742ab370f6864b6ce0e578b;p=scpubgit%2Fstemmatology.git

better error handling of missing / forbidden traditions
---

diff --git a/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm b/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm
index 264cef1..0b5b395 100644
--- a/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm
+++ b/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm
@@ -32,16 +32,24 @@ graph identified by $stemmaid.
 sub index :Path :Args(2) {
     my( $self, $c, $textid, $stemid ) = @_;
     my $m = $c->model('Directory');
+	$c->stash->{template} = 'stexaminer.tt'; 
+	
+	# Make sure the tradition exists and is viewable
 	my $tradition = $m->tradition( $textid );
+	unless( $tradition ) {
+		$c->response->status( 404 );
+		$c->stash->{'error'} = "No tradition with ID $textid";
+		return;
+	}	
 	my $ok = _check_permission( $c, $tradition );
 	return unless $ok;
+	
 	if( $tradition->stemma_count ) {
 		my $stemma = $tradition->stemma( $stemid );
 		$c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } );
 		$c->stash->{graphdot} = $stemma->editable({ linesep => ' ' });
 		$c->stash->{text_id} = $textid;
 		$c->stash->{text_title} = $tradition->name;
-		$c->stash->{template} = 'stexaminer.tt'; 
 		
 		# Get the analysis options
 		my( $use_type1, $ignore_sort ) = ( 0, 'none' );
@@ -109,8 +117,7 @@ sub _check_permission {
 
 	# ...nope. Forbidden!
 	$c->response->status( 403 );
-	$c->response->body( 'You do not have permission to view this tradition' );
-	$c->forward('View::Plain');
+	$c->stash->{'error'} = 'You do not have permission to view this tradition';
 	return 0;
 }
 
diff --git a/stemmaweb/root/src/stexaminer.tt b/stemmaweb/root/src/stexaminer.tt
index 50763ec..9867a8a 100644
--- a/stemmaweb/root/src/stexaminer.tt
+++ b/stemmaweb/root/src/stexaminer.tt
@@ -6,7 +6,11 @@
 <script type="text/javascript">
 var baseurl = "[% c.uri_for( '/stexaminer/' ) %]";
 var textid = '[% text_id %]';
+[% IF error -%]
+var readingstats = [];
+[% ELSE -%]
 var readingstats = [% reading_statistics %];
+[% END -%]
 var graphdot = '[% graphdot %]';
 </script>
 [% END -%]
@@ -18,6 +22,11 @@ var graphdot = '[% graphdot %]';
     	<h2>[% text_title %]</h2>
     	<p><span class="navlink" onClick="$('#options').dialog('open')">Analysis options</span></p>
     </div>
+    <div id="status">
+[% IF error -%]
+	    <span class="error">[% error %]</span>
+[% END -%]
+    </div>
     <div id="variants_table">
       <table>
 [% FOREACH row IN variants -%]