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