@trycourier/courier 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/http-client.js +4 -3
- package/package.json +1 -1
package/lib/http-client.js
CHANGED
|
@@ -93,7 +93,7 @@ exports.initHttpClient = function (_a) {
|
|
|
93
93
|
case 0:
|
|
94
94
|
searchParams = String(new URLSearchParams(config === null || config === void 0 ? void 0 : config.params));
|
|
95
95
|
searchQueryString = searchParams && "?" + searchParams;
|
|
96
|
-
fullUrl =
|
|
96
|
+
fullUrl = encodeURI("" + (baseUrl !== null && baseUrl !== void 0 ? baseUrl : '') + url + searchQueryString);
|
|
97
97
|
contentTypeHeader = body == null ? null : { "Content-Type": "application/json" };
|
|
98
98
|
idempotencyKeyHeader = (config === null || config === void 0 ? void 0 : config.idempotencyKey) ? { "Idempotency-Key": config.idempotencyKey }
|
|
99
99
|
: null;
|
|
@@ -107,12 +107,13 @@ exports.initHttpClient = function (_a) {
|
|
|
107
107
|
})];
|
|
108
108
|
case 1:
|
|
109
109
|
response = _b.sent();
|
|
110
|
-
parseAsJson = response.headers.get("content-
|
|
110
|
+
parseAsJson = response.headers.get("content-length") !== "0" &&
|
|
111
|
+
response.headers.get("content-type") === "application/json";
|
|
111
112
|
return [4 /*yield*/, (parseAsJson ? response.json() : response.text())];
|
|
112
113
|
case 2:
|
|
113
114
|
data = _b.sent();
|
|
114
115
|
if (!response.ok) {
|
|
115
|
-
throw new CourierHttpClientError(data.message || "
|
|
116
|
+
throw new CourierHttpClientError(data.message || "An unexpected error has occurred", { response: response, data: data });
|
|
116
117
|
}
|
|
117
118
|
return [2 /*return*/, { data: data }];
|
|
118
119
|
}
|