aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-02-17 13:50:39 +0800
committerGitHub <noreply@github.com>2018-02-17 13:50:39 +0800
commit9a5fd3f7840f84961265efc09ae79735b2f152db (patch)
tree4b7d1c708679fb228d47b5c17d35d641a6d8e76e
parent80eca307251a18ec466c9fd77c055277ca1236db (diff)
parentb703ccde9bc494b8715d11bb774136996e320228 (diff)
downloaddexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar.gz
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar.bz2
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar.lz
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar.xz
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.tar.zst
dexon-sol-tools-9a5fd3f7840f84961265efc09ae79735b2f152db.zip
Merge pull request #407 from 0xProject/fix/connect/empty-response
Do not JSON parse empty reponse
-rw-r--r--packages/connect/CHANGELOG.md4
-rw-r--r--packages/connect/src/http_client.ts9
2 files changed, 8 insertions, 5 deletions
diff --git a/packages/connect/CHANGELOG.md b/packages/connect/CHANGELOG.md
index 35e78c18c..8b88c3d20 100644
--- a/packages/connect/CHANGELOG.md
+++ b/packages/connect/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## v0.6.1 - _TBD, 2018_
+
+ * Fix JSON parse empty response (#407)
+
## v0.6.0 - _February 16, 2018_
* Add pagination options to HttpClient methods (#393)
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 9e5f0f448..cf0aaef0d 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -172,13 +172,12 @@ export class HttpClient implements Client {
body: JSON.stringify(payload),
headers,
});
- const json = await response.json();
+ const text = await response.text();
if (!response.ok) {
- const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${JSON.stringify(
- json,
- )}`;
+ const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${text}`;
throw Error(errorString);
}
- return json;
+ const result = !_.isEmpty(text) ? JSON.parse(text) : undefined;
+ return result;
}
}