From: Tara L Andrews Date: Tue, 11 Sep 2012 08:07:53 +0000 (+0200) Subject: update error http codes; guard against invalid stemma IDs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2bfac19751089df74b9382ef3d06180560cdca7f;p=scpubgit%2Fstemmaweb.git update error http codes; guard against invalid stemma IDs --- diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index c3812e7..5decf72 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -141,7 +141,7 @@ sub newtradition :Local :Args(0) { } } else { # Error unless we have a recognized filename extension - return _json_error( $c, 500, "Unrecognized file type extension $ext" ); + return _json_error( $c, 403, "Unrecognized file type extension $ext" ); } # Save the tradition if we have it, and return its data or else the @@ -177,7 +177,7 @@ sub textinfo :Local :Args(1) { my( $self, $c, $textid ) = @_; my $tradition = $c->model('Directory')->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -279,7 +279,7 @@ sub variantgraph :Local :Args(1) { my( $self, $c, $textid ) = @_; my $tradition = $c->model('Directory')->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -306,7 +306,7 @@ sub stemma :Local :Args(2) { my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -321,13 +321,15 @@ sub stemma :Local :Args(2) { # We are adding a new stemma. $stemma = $tradition->add_stemma( 'dot' => $dot ); $stemmaid = $tradition->stemma_count - 1; + } elsif( $stemmaid !~ /^\d+$/ ) { + return _json_error( $c, 403, "Invalid stemma ID specification $stemmaid" ); } elsif( $stemmaid < $tradition->stemma_count ) { # We are updating an existing stemma. $stemma = $tradition->stemma( $stemmaid ); $stemma->alter_graph( $dot ); } else { # Unrecognized stemma ID - return _json_error( $c, 500, "No stemma at index $stemmaid, cannot update" ); + return _json_error( $c, 404, "No stemma at index $stemmaid, cannot update" ); } } catch ( Text::Tradition::Error $e ) { return _json_error( $c, 500, $e->message ); @@ -383,13 +385,13 @@ sub stemmadot :Local :Args(2) { my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; my $stemma = $tradition->stemma( $stemmaid ); unless( $stemma ) { - return _json_error( $c, 500, "Tradition $textid has no stemma ID $stemmaid" ); + return _json_error( $c, 404, "Tradition $textid has no stemma ID $stemmaid" ); } # Get the dot and transmute its line breaks to literal '|n' $c->stash->{'result'} = { 'dot' => $stemma->editable( { linesep => '|n' } ) };