@ztimson/utils 0.23.11 → 0.23.12
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.cjs +20 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +20 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1036,6 +1036,20 @@ function errorFromCode(code, message) {
|
|
|
1036
1036
|
return new CustomError(message, code);
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
|
+
class HttpResponse extends Response {
|
|
1040
|
+
constructor(resp, stream) {
|
|
1041
|
+
super(stream, { headers: resp.headers, status: resp.status, statusText: resp.statusText });
|
|
1042
|
+
__publicField(this, "data");
|
|
1043
|
+
__publicField(this, "ok");
|
|
1044
|
+
__publicField(this, "redirected");
|
|
1045
|
+
__publicField(this, "type");
|
|
1046
|
+
__publicField(this, "url");
|
|
1047
|
+
this.ok = resp.ok;
|
|
1048
|
+
this.redirected = resp.redirected;
|
|
1049
|
+
this.type = resp.type;
|
|
1050
|
+
this.url = resp.url;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1039
1053
|
const _Http = class _Http {
|
|
1040
1054
|
constructor(defaults = {}) {
|
|
1041
1055
|
__publicField(this, "interceptors", {});
|
|
@@ -1107,13 +1121,13 @@ const _Http = class _Http {
|
|
|
1107
1121
|
push();
|
|
1108
1122
|
}
|
|
1109
1123
|
});
|
|
1110
|
-
resp
|
|
1111
|
-
if (opts.decode
|
|
1124
|
+
resp = new HttpResponse(resp, stream);
|
|
1125
|
+
if (opts.decode !== false) {
|
|
1112
1126
|
const content = (_b = resp.headers.get("Content-Type")) == null ? void 0 : _b.toLowerCase();
|
|
1113
|
-
if (content == null ? void 0 : content.includes("form")) resp.data = await resp.
|
|
1114
|
-
else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.
|
|
1115
|
-
else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.
|
|
1116
|
-
else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.
|
|
1127
|
+
if (content == null ? void 0 : content.includes("form")) resp.data = await resp.formData();
|
|
1128
|
+
else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.json();
|
|
1129
|
+
else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.text();
|
|
1130
|
+
else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.blob();
|
|
1117
1131
|
}
|
|
1118
1132
|
if (resp.ok) res(resp);
|
|
1119
1133
|
else rej(resp);
|