aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/http_client.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-01-13 04:18:03 +0800
committerGitHub <noreply@github.com>2018-01-13 04:18:03 +0800
commit80a46d14beec7544849247f9362db3de3bae04a8 (patch)
tree8ff60593fcd1b66c22bc9908bd96dead6653df41 /packages/connect/src/http_client.ts
parent97e01d7a427e18d740f692ccc8a65225b9d36268 (diff)
parentfbcbf066cdc13b99d1d280e131c01bd5456d90ae (diff)
downloaddexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar.gz
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar.bz2
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar.lz
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar.xz
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.tar.zst
dexon-sol-tools-80a46d14beec7544849247f9362db3de3bae04a8.zip
Merge pull request #318 from 0xProject/feature/httpClientErrorImprovements
Improve HttpClient errors
Diffstat (limited to 'packages/connect/src/http_client.ts')
-rw-r--r--packages/connect/src/http_client.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 5604a9607..3df77b0f0 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -20,6 +20,7 @@ import {
} from './types';
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';
+const TRAILING_SLASHES_REGEX = /\/+$/;
/**
* This class includes all the functionality related to interacting with a set of HTTP endpoints
* that implement the standard relayer API v0
@@ -33,7 +34,7 @@ export class HttpClient implements Client {
*/
constructor(url: string) {
assert.isHttpUrl('url', url);
- this._apiEndpointUrl = url;
+ this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes
}
/**
* Retrieve token pair info from the API
@@ -130,20 +131,22 @@ export class HttpClient implements Client {
const stringifiedParams = queryString.stringify(params);
query = `?${stringifiedParams}`;
}
- const url = `${this._apiEndpointUrl}/v0${path}${query}`;
+ const url = `${this._apiEndpointUrl}${path}${query}`;
const headers = new Headers({
'content-type': 'application/json',
});
-
const response = await fetch(url, {
method: requestType,
body: JSON.stringify(payload),
headers,
});
+ const json = await response.json();
if (!response.ok) {
- throw Error(response.statusText);
+ const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${JSON.stringify(
+ json,
+ )}`;
+ throw Error(errorString);
}
- const json = await response.json();
return json;
}
}