package Catalyst::View::Errors::JSON;
use Moose;
use JSON::MaybeXS;
use CatalystX::Utils::ContentNegotiation;
use CatalystX::Utils::ErrorMessages;
extends 'Catalyst::View';
has extra_encoder_args =
JSON::MaybeXS->new(utf8=>1, %{shift->extra_encoder_args}) },
);
sub http_default {
my ($self, $c, $code, %args) = @_;
my $message_info = $self->finalize_message_info($c, $code, %args);
my $json
= $self->render_json($c, $message_info);
$c->response->body($json);
$c->response->content_type('application/json');
$c->response->status($code);
}
sub finalize_message_info {
my ($self, $c
= (
'text/html' => 'Errors::HTML',
'text/plain' => 'Errors::Text',
'application/json' => 'Errors::JSON',
);
my %views = %DEFAULT_ERROR_VIEWS;
my @accepted = ();
my $default_media_type = 'tex
' => 'Errors::HTML',
'text/plain' => 'Errors::Text',
'application/json' => 'Errors::JSON',
},
},
);
__PACKAGE__->setup();
__PACKAGE__->meta->make_immu
table();
By default we map the media types C<text/html>, C<text/plain> and C<application/json> to
cooresponding views. This views are injected automatically if you don't provide subclasses
or your o
<Catalyst> error page is in HTML and if your client is requesting
JSON we'll return a properly formatted response in C<application/json>.
B<NOTE> if you are in CATALYST_DEBUG mode then all HTTP 500 e
TP errors using
proper content negotiation. Out of the box it support returning errors in HTML,
JSON and Text, with errors in a number of common languages. Patches to support more
languages and me
rs>, L<Catalyst::View::Errors::HTML>,
L<Catalyst::View::Errors::Text>, L<Catalyst::View::Errors::JSON>,
L<Catalyst::ActionRole::RenderErrors>.
=head1 AUTHOR
John Napiorkowski L<email:jjnapior