Subject: | No CRUD errors in Ext.Direct [PATCH] |
Hi,
CRUD errors in C::C..ExtJS::REST ('Object could not be found' etc)
set the HTTP status code via $self->status_not_found.
In C::C::ExtJS::Direct::API the status code is ignored and the error
is returned as a plain message in the JSON response with status 200.
Unfortunately ExtJS sees this as a success. No error is reported and the
store and the database get out of sync.
There are two possibilities to fix this:
1. return {'success': false} for each failed request
2. return an exception for each failed request
I choose alternative 2 for the patch because it's easier (just two
additional lines). The error message could use a little more work but I
wanted to keep the patch as small as possible.
Best regards
Herbert
Subject: | extjs_exception.patch |
diff -Naur ./lib/CatalystX/Controller/ExtJS/Direct/API.pm ../CatalystX-ExtJS-1.120000-modified/lib/CatalystX/Controller/ExtJS/Direct/API.pm
--- ./lib/CatalystX/Controller/ExtJS/Direct/API.pm 2010-08-17 12:57:25.000000000 +0200
+++ ../CatalystX-ExtJS-1.120000-modified/lib/CatalystX/Controller/ExtJS/Direct/API.pm 2010-08-24 12:56:56.571772151 +0200
@@ -148,6 +148,8 @@
eval {
$c->visit($route->build_url( $req->{data} ));
my $response = $c->res;
+ my $status = $response->status;
+ die "Status $status:\n" if $status >= 400;
if ( $response->content_type eq 'application/json' ) {
(my $res_body = $response->body) =~ s/^\xEF\xBB\xBF//; # remove BOM
my $json = JSON::Any->new->decode( $res_body );
diff -Naur ./t/direct/router/rest_extjs.t ../CatalystX-ExtJS-1.120000-modified/t/direct/router/rest_extjs.t
--- ./t/direct/router/rest_extjs.t 2010-08-17 12:57:25.000000000 +0200
+++ ../CatalystX-ExtJS-1.120000-modified/t/direct/router/rest_extjs.t 2010-08-24 11:50:29.366989791 +0200
@@ -40,6 +40,20 @@
POST $api->{url},
Content_Type => 'application/json',
Content => q(
+ {"action":"User","method":"destroy","data":[{"rows":"4"}],"type":"rpc","tid":3}
+ ),
+ ),
+ 'delete non-existing user: request succeeds'
+);
+$mech->content_contains('exception', '... but response contains exception');
+
+count_users(3);
+
+ok(
+ $mech->request(
+ POST $api->{url},
+ Content_Type => 'application/json',
+ Content => q(
{"action":"User","method":"destroy","data":[{"rows":"1"}],"type":"rpc","tid":3}
)
),