api-def 0.6.0-alpha13 → 0.6.0-alpha14
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/cjs/Requester.js +10 -10
- package/esm/Requester.js +10 -10
- package/package.json +1 -1
package/cjs/Requester.js
CHANGED
|
@@ -211,7 +211,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
|
|
|
211
211
|
});
|
|
212
212
|
}); };
|
|
213
213
|
var parseResponse = function (context, response, error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
214
|
-
var
|
|
214
|
+
var parsedResponse_1, contentType, inferredResponseType, data, decodedData;
|
|
215
215
|
var _a;
|
|
216
216
|
return __generator(this, function (_b) {
|
|
217
217
|
switch (_b.label) {
|
|
@@ -219,12 +219,12 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
219
219
|
if (!response) return [3 /*break*/, 2];
|
|
220
220
|
return [4 /*yield*/, context.backend.convertResponse(context, response)];
|
|
221
221
|
case 1:
|
|
222
|
-
|
|
222
|
+
parsedResponse_1 = _b.sent();
|
|
223
223
|
// lowercase all header names
|
|
224
|
-
|
|
225
|
-
headers[header.toLowerCase()] =
|
|
224
|
+
parsedResponse_1.headers = Object.keys(parsedResponse_1.headers).reduce(function (headers, header) {
|
|
225
|
+
headers[header.toLowerCase()] = parsedResponse_1.headers[header];
|
|
226
226
|
}, {});
|
|
227
|
-
contentType =
|
|
227
|
+
contentType = parsedResponse_1.headers["Content-Type"];
|
|
228
228
|
inferredResponseType = ApiUtils_1.inferResponseType(contentType);
|
|
229
229
|
if (!error) {
|
|
230
230
|
// expand to array buffer once we support that in inferResponseType
|
|
@@ -232,13 +232,13 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
232
232
|
throw RequestError_1.convertToRequestError({
|
|
233
233
|
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
234
234
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
235
|
-
response:
|
|
235
|
+
response: parsedResponse_1,
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
// transform arrayBuffer to json
|
|
239
239
|
if (inferredResponseType === "arraybuffer" && context.responseType === "json") {
|
|
240
|
-
if (
|
|
241
|
-
typeof
|
|
240
|
+
if (parsedResponse_1.data &&
|
|
241
|
+
typeof parsedResponse_1.data === "object") {
|
|
242
242
|
data = response.data;
|
|
243
243
|
if (((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer") {
|
|
244
244
|
try {
|
|
@@ -249,14 +249,14 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
249
249
|
throw RequestError_1.convertToRequestError({
|
|
250
250
|
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
251
251
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
252
|
-
response:
|
|
252
|
+
response: parsedResponse_1,
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
return [2 /*return*/,
|
|
259
|
+
return [2 /*return*/, parsedResponse_1];
|
|
260
260
|
case 2: return [2 /*return*/, response];
|
|
261
261
|
}
|
|
262
262
|
});
|
package/esm/Requester.js
CHANGED
|
@@ -207,7 +207,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
|
|
|
207
207
|
});
|
|
208
208
|
}); };
|
|
209
209
|
var parseResponse = function (context, response, error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
210
|
-
var
|
|
210
|
+
var parsedResponse_1, contentType, inferredResponseType, data, decodedData;
|
|
211
211
|
var _a;
|
|
212
212
|
return __generator(this, function (_b) {
|
|
213
213
|
switch (_b.label) {
|
|
@@ -215,12 +215,12 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
215
215
|
if (!response) return [3 /*break*/, 2];
|
|
216
216
|
return [4 /*yield*/, context.backend.convertResponse(context, response)];
|
|
217
217
|
case 1:
|
|
218
|
-
|
|
218
|
+
parsedResponse_1 = _b.sent();
|
|
219
219
|
// lowercase all header names
|
|
220
|
-
|
|
221
|
-
headers[header.toLowerCase()] =
|
|
220
|
+
parsedResponse_1.headers = Object.keys(parsedResponse_1.headers).reduce(function (headers, header) {
|
|
221
|
+
headers[header.toLowerCase()] = parsedResponse_1.headers[header];
|
|
222
222
|
}, {});
|
|
223
|
-
contentType =
|
|
223
|
+
contentType = parsedResponse_1.headers["Content-Type"];
|
|
224
224
|
inferredResponseType = inferResponseType(contentType);
|
|
225
225
|
if (!error) {
|
|
226
226
|
// expand to array buffer once we support that in inferResponseType
|
|
@@ -228,13 +228,13 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
228
228
|
throw convertToRequestError({
|
|
229
229
|
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
230
230
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
231
|
-
response:
|
|
231
|
+
response: parsedResponse_1,
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
234
|
// transform arrayBuffer to json
|
|
235
235
|
if (inferredResponseType === "arraybuffer" && context.responseType === "json") {
|
|
236
|
-
if (
|
|
237
|
-
typeof
|
|
236
|
+
if (parsedResponse_1.data &&
|
|
237
|
+
typeof parsedResponse_1.data === "object") {
|
|
238
238
|
data = response.data;
|
|
239
239
|
if (((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer") {
|
|
240
240
|
try {
|
|
@@ -245,14 +245,14 @@ var parseResponse = function (context, response, error) { return __awaiter(void
|
|
|
245
245
|
throw convertToRequestError({
|
|
246
246
|
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
247
247
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
248
|
-
response:
|
|
248
|
+
response: parsedResponse_1,
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
return [2 /*return*/,
|
|
255
|
+
return [2 /*return*/, parsedResponse_1];
|
|
256
256
|
case 2: return [2 /*return*/, response];
|
|
257
257
|
}
|
|
258
258
|
});
|