<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 11, 2014 at 7:06 PM, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">[...]<br>
</span>Just thought I'd follow up on this. It turned out that the problem was<br>
that my text to render to the screen was a reference to an object that<br>
normally stringified into the required text (Log::Report::Message).<br>
However, because the serializer was simply checking for a reference, the<br>
object didn't have a chance to stringify itself, and instead an attempt<br>
was made to convert the object into JSON.<br>
<br>
The fix was easy (just stringify first), but I did wonder whether a<br>
better error message could be displayed somehow, as it took me rather a<br>
long time to debug. I came to the conclusion that it couldn't, but if<br>
anyone has any ideas then please let me know.<br></blockquote><div><br></div><div>I have two comments left:</div><div>1. I don't think API requests should be conflated with regular page rendering. This should be a clear "I send you JSON, I receive JSON" and a clear "I send a request from the browser to render output for the user and expect to receive HTML back". There is one exception in which you might want to make a JSON request return a rendered HTML which you could stick in the page ("template 'parts/box' => {...}, { layout => undef };") but that's something which would then also get serialized and returned back. Imagine an API on the frontend having to account for either JSON or HTML, not knowing how an error would be returned. It could be a JSON structure with the error or an HTML which itself is an error. It's gonna have a bad time. :)</div><div><br></div><div>2. If you found the error unhelpful, we should definitely fix it. That's about it. :)</div><div><br></div><div>If you could open an issue on Github so we can easily add all the context and track it there, we would be more than happy to help. You could make suggestions for what you think a better error message could be.</div><div><br></div><div>Thanks! :)</div></div></div></div>