<div dir="ltr">we've had this issue for a while since we run REST services and webapp out of same code base.<div><br></div><div>We do this:</div><div><br></div><div><div>hook before_error_init => sub {</div><div> my $err_obj = shift;</div>
<div><br></div><div> if ( request->path !~ m{^/api/} && ( my $ser = setting('serializer') ) ) {</div><div> set 'serializer', undef;</div><div> $err_obj->{_save_serializer} = $ser;</div>
<div> }</div><div>};</div></div><div><br></div><div>And then restore it:</div><div><br></div><div><div>hook after_error_render => sub {</div><div> my $response = shift;</div><div> my $err_obj = vars->{_save_err_obj};</div>
<div><br></div><div> if ( my $ser = delete $err_obj->{_save_serializer} ) {</div><div> set 'serializer', $ser;</div><div> }</div><div>};</div></div><div><br></div><div>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. </div>
<div><br></div><div>HTH,</div><div><br></div><div>Lee</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 14, 2014 at 5:20 AM, David Precious <span dir="ltr"><<a href="mailto:davidp@preshweb.co.uk" target="_blank">davidp@preshweb.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Thu, 13 Mar 2014 18:57:04 -0600<br>
Warren Young <<a href="mailto:warren@etr-usa.com">warren@etr-usa.com</a>> wrote:<br>
<br>
> Apparently you cannot have both<br>
><br>
> serializer: "JSON"<br>
> show_errors: 1<br>
><br>
> in your config.yml. Enabling the automatic JSON serializer defeats<br>
> the error screen, returning the exception error object as JSON to the<br>
> client:<br>
</div><snip><br>
<br>
You could argue that's correct and desired behaviour - if you have set<br>
serialiser: "JSON", you are, presumably, writing an API, which will be<br>
used by API consumers expecting JSON. Suddenly dumping a HTML error<br>
page at them instead of the JSON they were expecting would be silly and<br>
wrong - returning JSON describing the error seems much more sane.<br>
<br>
So, I wouldn't say it breaks the error page, I'd say it's logical<br>
behaviour.<br>
<br>
If you don't want it, though, you could probably get round it with<br>
Yanick's suggestion of using before_serializer.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
David Precious ("bigpresh") <<a href="mailto:davidp@preshweb.co.uk">davidp@preshweb.co.uk</a>><br>
<a href="http://www.preshweb.co.uk/" target="_blank">http://www.preshweb.co.uk/</a> <a href="http://www.preshweb.co.uk/twitter" target="_blank">www.preshweb.co.uk/twitter</a><br>
<a href="http://www.preshweb.co.uk/linkedin" target="_blank">www.preshweb.co.uk/linkedin</a> <a href="http://www.preshweb.co.uk/facebook" target="_blank">www.preshweb.co.uk/facebook</a><br>
<a href="http://www.preshweb.co.uk/cpan" target="_blank">www.preshweb.co.uk/cpan</a> <a href="http://www.preshweb.co.uk/github" target="_blank">www.preshweb.co.uk/github</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>