api-def 0.14.0 → 0.14.1
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.
|
@@ -112,9 +112,6 @@ class FetchRequestBackend {
|
|
|
112
112
|
let responded = false;
|
|
113
113
|
const body = context.getParsedBody();
|
|
114
114
|
const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormDataLike(body) && !(body instanceof URLSearchParams);
|
|
115
|
-
if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
|
|
116
|
-
Utils.assertFetchCompatibleFormData(body);
|
|
117
|
-
}
|
|
118
115
|
const headers = Utils.assign({
|
|
119
116
|
// logic from axios
|
|
120
117
|
"Content-Type": bodyJsonify ? "application/json;charset=utf-8" : undefined,
|
|
@@ -143,7 +140,25 @@ class FetchRequestBackend {
|
|
|
143
140
|
if (requestConfig.debug) {
|
|
144
141
|
console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
|
|
145
142
|
}
|
|
146
|
-
|
|
143
|
+
let request;
|
|
144
|
+
try {
|
|
145
|
+
request = new Request(url.href, fetchOptions);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (context.validation.bodyEncoding === "multipart/form-data") {
|
|
149
|
+
throw Object.assign(new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation"), {
|
|
150
|
+
cause: error,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
|
|
156
|
+
const contentType = request.headers.get("content-type");
|
|
157
|
+
if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
|
|
158
|
+
throw new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const promise = this.fetch(request).then((response) => {
|
|
147
162
|
responded = true;
|
|
148
163
|
if (!response.ok) {
|
|
149
164
|
const error = new FetchError("Fetch failed");
|
|
@@ -77,9 +77,6 @@ export default class FetchRequestBackend {
|
|
|
77
77
|
let responded = false;
|
|
78
78
|
const body = context.getParsedBody();
|
|
79
79
|
const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormDataLike(body) && !(body instanceof URLSearchParams);
|
|
80
|
-
if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
|
|
81
|
-
Utils.assertFetchCompatibleFormData(body);
|
|
82
|
-
}
|
|
83
80
|
const headers = Utils.assign({
|
|
84
81
|
// logic from axios
|
|
85
82
|
"Content-Type": bodyJsonify ? "application/json;charset=utf-8" : undefined,
|
|
@@ -108,7 +105,25 @@ export default class FetchRequestBackend {
|
|
|
108
105
|
if (requestConfig.debug) {
|
|
109
106
|
console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
|
|
110
107
|
}
|
|
111
|
-
|
|
108
|
+
let request;
|
|
109
|
+
try {
|
|
110
|
+
request = new Request(url.href, fetchOptions);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (context.validation.bodyEncoding === "multipart/form-data") {
|
|
114
|
+
throw Object.assign(new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation"), {
|
|
115
|
+
cause: error,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
|
|
121
|
+
const contentType = request.headers.get("content-type");
|
|
122
|
+
if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
|
|
123
|
+
throw new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const promise = this.fetch(request).then((response) => {
|
|
112
127
|
responded = true;
|
|
113
128
|
if (!response.ok) {
|
|
114
129
|
const error = new FetchError("Fetch failed");
|