On Wed Mar 18 10:16:13 2009, TIMB wrote:
Show quoted text> > search=foo wouldn't make any sense.
>
> I know it wouldn't make any sense, I just don't want the app to crash!
> :)
>
> Looks like the newer code won't have the same problem because it
> checks {search} is a hash ref
> else fallsback on JSON::Any. But whet does JSON::Any do if you feed it
> gibberish? It may throw
> an exception (e.g. see get_max_size). So I'd suggest an eval {} and
> log $ on error.
I've refactored this new JSON stuff to better handle errors. Now it will
return a 400 and an error message in the case of being unable to parse
this. This behaviour is best described with this test from
list_json_search.t:
my $uri = URI->new( $artist_list_url );
$uri->query_form({ 'search' => '{"gibberish}' });
my $req = GET( $uri, 'Accept' => 'text/x-json' );
$mech->request($req);
cmp_ok( $mech->status, '==', 400, 'attempt with gibberish json
not okay' );
my $response = JSON::Syck::Load( $mech->content);
is_deeply( { messages => ['can not parse search arg'], success
=> 'false' }, $response, 'correct data returned for gibberish in search' );
Show quoted text> Also there's no way to configure the JSON::Any object (or cache it to
> avoid recreating each time).
> Perhaps add an accessor to get the json convertor object instance.
Might be sensible, but I'm going to shelve this optimisation until the
next release when the JSON feature is more mature.