aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/http_client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/connect/src/http_client.ts')
-rw-r--r--packages/connect/src/http_client.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 5604a9607..c30b499a2 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
@@ -134,16 +135,18 @@ export class HttpClient implements Client {
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;
}
}