From 6dd2a0e22253c78775afdbbbc52b8a100c79a79c Mon Sep 17 00:00:00 2001 From: Constantin Titarenko Date: Thu, 18 Aug 2016 19:49:09 +0300 Subject: [PATCH 1/2] don't parse body if status code is 204 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 1a77c6f..2aeaa4d 100644 --- a/index.js +++ b/index.js @@ -270,7 +270,7 @@ function run_xhr(options) { xhr.body = xhr.responseText if(options.json) { - try { xhr.body = JSON.parse(xhr.responseText) } + try { xhr.body = xhr.statusCode == 204 ? undefined : JSON.parse(xhr.responseText) } catch (er) { return options.callback(er, xhr) } } From add82f54cff04fc769ad52ea9d14e0a14f1949cd Mon Sep 17 00:00:00 2001 From: Constantin Titarenko Date: Mon, 17 Oct 2016 23:02:38 +0300 Subject: [PATCH 2/2] do not parse empty body --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2aeaa4d..afb72c4 100644 --- a/index.js +++ b/index.js @@ -270,7 +270,7 @@ function run_xhr(options) { xhr.body = xhr.responseText if(options.json) { - try { xhr.body = xhr.statusCode == 204 ? undefined : JSON.parse(xhr.responseText) } + try { xhr.body = xhr.responseText && JSON.parse(xhr.responseText) || undefined } catch (er) { return options.callback(er, xhr) } }