@katsunami ... I've been getting the Error 500 code for maybe 2 months, but this is a different error (as described).
The difference for me is that when I get the Error 500 code I'm in the India store, on this occasion I've been in the US store (because the Contest codes don't work in India)
I see the logic in the code you've written. Maybe you should delete it because if Kobo haven't already worked it out then you've done the job for them.