Wednesday, December 12, 2012

Re: JSONResponseMixin: Best handle "context" before dumping it to JSON?

Hi Russ! Wow, thanks so much for the quick reply and additional details! :)

On Wed, Dec 12, 2012 at 7:12 PM, Russell Keith-Magee
<russell@keith-magee.com> wrote:
> Can you use a try-catch to flag encoding problems? Sure - that's a
> completely reasonable solution.
> Is a blanket try-catch a bad idea? Yes, because it hides all sins. The
> exceptions you're expecting are quite predictable -- if dumps() can't encode
> the object, you're going to get a TypeError. Therefore it makes sense to
> catch the TypeError, and provide a response that indicates that encoding was
> the problem. If you catch *all* exceptions, and just assume that encoding
> was the problem, then the "once in a million that happens 9 times out of 10"
> will be some other error generated by the serialisation of the object that
> *isn't* a type encoding error (an attribute error in your serializer, for
> example). If you're masking those errors, they're much harder to find.

Awesome! That makes total sense!

For now, I think I'll add a try/catch TypeError check and then test
thoroughly for corner cases to see if I need further data-type
handling.

Thanks again for the pro help an assistance! I owe you one! ;)

Have a nice night.

Cheers,
Micky

--
Micky Hulse
Web Content Editor
The Register-Guard
3500 Chad Drive
Eugene, OR 97408
Phone: (541) 338-2621
Fax: (541) 683-7631
Web: <http://www.registerguard.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate