Subject: | malformed json on empty but valid response |
There are several POST calls to the jira api which will simply return a status code of 204 and no content. This is partially JIRA's fault because they return a content header of "application/json;charset=UTF-8" even though they are not returning valid json. Unfortunately, JIRA::Rest dies in these cases with the following error:
malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before \"(end of string)\")
even though there was actually nothing wrong with the response.
It seems like in those cases the code should simply not try to parse the json content and return. Something like this:
--- /usr/lib/perl5/site_perl/5.8.8/JIRA/REST.pm 2013-08-16 10:38:47.000000000 -0600
+++ REST.pm 2013-12-12 13:57:10.000000000 -0700
@@ -133,6 +133,7 @@
if (! defined $type) {
return;
} elsif ($type =~ m:^application/json:i) {
+ return if ! $content;
return $self->{json}->decode($content);
} elsif ($type =~ m:^text/plain:i) {
return $content;