shred-api-client 2.3.5-rc.6 → 2.3.5-rc.8
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/dist/index.js +25 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ __export(index_exports, {
|
|
|
48
48
|
module.exports = __toCommonJS(index_exports);
|
|
49
49
|
|
|
50
50
|
// src/util/HTTPClient.ts
|
|
51
|
-
var
|
|
51
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
52
52
|
var HOSTS = {
|
|
53
53
|
prod: "https://api.shreditapp.com",
|
|
54
54
|
staging: "https://api.staging.shreditapp.com",
|
|
@@ -61,7 +61,6 @@ var OLD_HOSTS = {
|
|
|
61
61
|
};
|
|
62
62
|
var HTTPClient = class {
|
|
63
63
|
async makeRequest(env, uri, method, data, context, useLegacyApi) {
|
|
64
|
-
var _a;
|
|
65
64
|
const hostDict = useLegacyApi ? OLD_HOSTS : HOSTS;
|
|
66
65
|
const host = hostDict[env] || hostDict.staging;
|
|
67
66
|
const url = host + uri;
|
|
@@ -74,40 +73,37 @@ var HTTPClient = class {
|
|
|
74
73
|
if (context == null ? void 0 : context.requestId) {
|
|
75
74
|
headers["X-Request-ID"] = context.requestId;
|
|
76
75
|
}
|
|
76
|
+
const fetchOptions = {
|
|
77
|
+
method,
|
|
78
|
+
headers
|
|
79
|
+
};
|
|
80
|
+
if (method !== "GET" && data) {
|
|
81
|
+
fetchOptions.body = useLegacyApi ? new URLSearchParams(data).toString() : JSON.stringify(data);
|
|
82
|
+
}
|
|
77
83
|
try {
|
|
78
|
-
const response = await
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const response = await (0, import_cross_fetch.default)(url, fetchOptions);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorText = await response.text();
|
|
87
|
+
throw {
|
|
88
|
+
status: response.status,
|
|
89
|
+
statusText: response.statusText,
|
|
90
|
+
body: errorText
|
|
91
|
+
};
|
|
92
|
+
}
|
|
86
93
|
try {
|
|
87
|
-
return
|
|
94
|
+
return await response.json();
|
|
88
95
|
} catch {
|
|
89
|
-
return response.
|
|
96
|
+
return await response.text();
|
|
90
97
|
}
|
|
91
|
-
} catch (
|
|
92
|
-
const error = err;
|
|
98
|
+
} catch (error) {
|
|
93
99
|
let parsedBody = {};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
parsedBody = {
|
|
99
|
-
message: ((_a = error.response.data) == null ? void 0 : _a.message) || error.response.statusText || "Unknown error"
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
throw {
|
|
103
|
-
message: parsedBody.message || "Unexpected error occurred",
|
|
104
|
-
status: error.response.status,
|
|
105
|
-
body: error.response.data,
|
|
106
|
-
original: error
|
|
107
|
-
};
|
|
100
|
+
try {
|
|
101
|
+
parsedBody = error.body ? JSON.parse(error.body) : {};
|
|
102
|
+
} catch {
|
|
103
|
+
parsedBody = { message: error.body || "Unknown error" };
|
|
108
104
|
}
|
|
109
105
|
throw {
|
|
110
|
-
message:
|
|
106
|
+
message: parsedBody.message || "Unexpected error occurred",
|
|
111
107
|
original: error
|
|
112
108
|
};
|
|
113
109
|
}
|