pjf / WebService-HabitRPG

Access the HabitRPG API from Perl
8 stars 5 forks source link

"malformed JSON string" #32

Closed toddgrotenhuis closed 7 years ago

toddgrotenhuis commented 11 years ago

I have gotten this message just a handful of times. I suspect it happens when an egg or potion is dropped. (a case that may not be handled by the results parser?) It happens when "plussing" an item.

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "<html>\n<head>\n    ...") at /Library/Perl/5.12/JSON/Any.pm line 571.

pjf commented 11 years ago

Aha! Having that happen when there's a drop makes perfect sense, since AFAIK the API has no way of signalling them. I suspect it's giving back some HTML page that hrpg then proceeds to choke up.

I'll report this upstream, but will leave this ticket open because I may be able to produce a workaround. :)

pjf commented 11 years ago

I've got a workaround in dev for this. It's not elegant, but I'm testing it now. If it seems to be catching the error then it will be in the next release.

This can't be properly fixed until the upstream bug is resolved.

pjf commented 11 years ago

The latest release (0.18) now has a workaround. There's a chance it may report an item has dropped on a general server error, but it gets around the problem of an ugly error when we don't get back valid JSON, and it should work even if you're doing something like a +5 to increment a task multiple times.

pjf@qapla:~$ hrpg + issue

Updating Fix any issue (x1) (80e85523-245c-4f00-be28-347180754b9a)

Looks like an item dropped! Check http://habitrpg.com/ to see what it is.
HP: 38/50 (+0.00)
XP: 86/300 (+8.50)
GP: 44.60 (+0.97)

As always, you can install with cpanm WebService::HabitRPG (although it may need an hour or so for all the CPAN mirrors to pick up on the new release).

hoelzro commented 7 years ago

This is fixed in version 0.30 of the module!