[dancer-users] Incorrect attempts to serialize HTML

Sawyer X xsawyerx at gmail.com
Wed Nov 12 09:23:51 GMT 2014

On Tue, Nov 11, 2014 at 7:06 PM, Andrew Beverley <andy at andybev.com> wrote:

> [...]
> Just thought I'd follow up on this. It turned out that the problem was
> that my text to render to the screen was a reference to an object that
> normally stringified into the required text (Log::Report::Message).
> However, because the serializer was simply checking for a reference, the
> object didn't have a chance to stringify itself, and instead an attempt
> was made to convert the object into JSON.
> The fix was easy (just stringify first), but I did wonder whether a
> better error message could be displayed somehow, as it took me rather a
> long time to debug. I came to the conclusion that it couldn't, but if
> anyone has any ideas then please let me know.

I have two comments left:
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.

2. If you found the error unhelpful, we should definitely fix it. That's
about it. :)

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.

Thanks! :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20141112/e2e9e3e4/attachment.html>

More information about the dancer-users mailing list