we've had this issue for a while since we run REST services and webapp out of same code base.
We do this:
hook before_error_init => sub {
my $err_obj = shift;
if ( request->path !~ m{^/api/} && ( my $ser = setting('serializer') ) ) {
set 'serializer', undef;
$err_obj->{_save_serializer} = $ser;
}
};
And then restore it:
hook after_error_render => sub {
my $response = shift;
my $err_obj = vars->{_save_err_obj};
if ( my $ser = delete $err_obj->{_save_serializer} ) {
set 'serializer', $ser;
}
};
I could see adding a config option to only do this in dev or test environments since i'd guess in production, you would want to log the error in JSON.
HTH,
Lee