[Catalyst-commits] r14508 - in CatalystX-CRUD/CatalystX-CRUD/trunk: . lib/CatalystX lib/CatalystX/CRUD lib/CatalystX/CRUD/Iterator lib/CatalystX/CRUD/Model lib/CatalystX/CRUD/ModelAdapter lib/CatalystX/CRUD/Object lib/CatalystX/CRUD/Test t
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Fri Feb 28 22:46:19 GMT 2014
Author: karpet
Date: 2014-02-28 22:46:19 +0000 (Fri, 28 Feb 2014)
New Revision: 14508
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t
CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t
Log:
EXPERIMENTAL: return 404 response when object fails to load
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2014-02-28 22:46:19 UTC (rev 14508)
@@ -1,5 +1,8 @@
Revision history for CatalystX-CRUD
+0.57 xxx
+ - failure to load object now returns 404 rather than throwing a 500.
+
0.56 28 Feb 2014
- remove : character from rxOp param in internal Search::QueryParser::SQL
constructor. This allows for finding url values like http://foo/bar
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -13,6 +13,7 @@
use MRO::Compat;
use mro 'c3';
use Data::Dump qw( dump );
+use Try::Tiny;
__PACKAGE__->mk_accessors(
qw(
@@ -42,7 +43,7 @@
# apply Role *after* we declare accessors above
with 'CatalystX::CRUD::ControllerRole';
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
@@ -170,10 +171,20 @@
}
my @arg = ( defined $pk_is_null || !$id ) ? () : (@pk);
$c->log->debug( "fetch: " . dump \@arg ) if $c->debug;
- $c->stash->{object} = $self->do_model( $c, 'fetch', @arg );
- if ( $self->has_errors($c) or !$c->stash->{object} ) {
+
+ try {
+ $c->stash->{object} = $self->do_model( $c, 'fetch', @arg );
+ if ( $self->has_errors($c) or !$c->stash->{object} ) {
+ $self->throw_error( 'No such ' . $self->model_name );
+ }
+ }
+ catch {
+ $c->res->status(404);
+ $c->res->body( 'No such ' . $self->model_name );
+
+ # re-throw so we interrupt chain.
$self->throw_error( 'No such ' . $self->model_name );
- }
+ };
}
=head2 create
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -3,7 +3,7 @@
use warnings;
use Carp;
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -4,7 +4,7 @@
use Carp;
use base qw( CatalystX::CRUD );
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -10,7 +10,7 @@
__PACKAGE__->mk_accessors(qw( inc_path ));
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
# test whether symlink() works at compile time
my $SYMLINK_SUPPORTED = eval { symlink( "", "" ); 1 };
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -9,7 +9,7 @@
__PACKAGE__->mk_accessors(qw( use_ilike use_lower ne_sign ));
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -9,7 +9,7 @@
Catalyst::Model
);
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
__PACKAGE__->mk_accessors(qw( object_class page_size ));
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -3,7 +3,7 @@
use warnings;
use base qw( CatalystX::CRUD::ModelAdapter );
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -13,7 +13,7 @@
__PACKAGE__->mk_accessors(qw( content file ));
__PACKAGE__->delegate_class('Path::Class::File');
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -12,7 +12,7 @@
__PACKAGE__->mk_ro_accessors(qw( delegate ));
__PACKAGE__->mk_classdata('delegate_class');
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -6,11 +6,12 @@
use MRO::Compat;
use mro 'c3';
use Data::Dump qw( dump );
+use Try::Tiny;
__PACKAGE__->mk_accessors(qw( enable_rpc_compat ));
__PACKAGE__->config( enable_rpc_compat => 0 );
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
#warn "REST VERSION = $VERSION";
@@ -313,8 +314,21 @@
sub _call_rpc_method_as_action {
my ( $self, $c, $rpc_method, $oid ) = @_;
- $self->fetch( $c, $oid );
+ my $break_chain = 0;
+ try {
+ $self->fetch( $c, $oid );
+ }
+ catch {
+ $c->log->debug( 'caught exception, res->status==' . $c->res->status )
+ if $c->debug;
+ if ( $c->res->status == 404 ) {
+ $c->log->debug('break chain with 404') if $c->debug;
+ $break_chain = 1;
+ }
+ };
+ return if $break_chain;
+
my $http_method = $self->req_method($c);
$c->log->debug("rpc: $http_method -> $rpc_method") if $c->debug;
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -13,7 +13,7 @@
__PACKAGE__->mk_ro_accessors(qw( count pager query results ));
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -8,7 +8,7 @@
__PACKAGE__->mk_accessors(qw( form_fields ));
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
@@ -129,8 +129,8 @@
if ( $self->has_errors($c) ) {
my $err = join( "\n", @{ $c->error } );
$c->log->error($err) if $c->debug;
- $c->res->body($err);
- $c->res->status(500);
+ $c->res->body($err) unless $c->res->body;
+ $c->res->status(500) unless $c->res->status;
$c->clear_errors;
}
}
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -7,7 +7,7 @@
__PACKAGE__->mk_accessors(qw( params fields ));
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2014-02-28 22:46:19 UTC (rev 14508)
@@ -4,7 +4,7 @@
use strict;
use Carp;
-our $VERSION = '0.56';
+our $VERSION = '0.56_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t 2014-02-28 22:46:19 UTC (rev 14508)
@@ -1,4 +1,4 @@
-use Test::More tests => 54;
+use Test::More tests => 56;
use strict;
use lib qw( lib t/lib );
use_ok('CatalystX::CRUD::Model::File');
@@ -181,5 +181,9 @@
ok( $res = request('/rest/file'), "/ request with no items" );
#dump $res;
-is( $res->code, 200, "/ request with no items == 200" );
-is( $res->content, "", "no content for no results" );
+is( $res->code, 200, "/ request with no items == 200" );
+is( $res->content, "", "no content for no results" );
+
+# request something we know doesn't exist
+ok( $res = request('/rest/file/nosuchfile'), "/ request with nosuchfile" );
+is( $res->code, 404, "nosuchfile == 404" );
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t 2014-02-28 22:15:43 UTC (rev 14507)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t 2014-02-28 22:46:19 UTC (rev 14508)
@@ -13,4 +13,4 @@
"GET new file with null pk"
);
-is( $res->code, 500, "exception thrown" );
+is( $res->code, 404, "no such file returns 404" );
More information about the Catalyst-commits
mailing list