1 | import { throwServerError } from "../utils/index.js";
|
2 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
3 | export function parseAndCheckHttpResponse(operations) {
|
4 | return function (response) { return response
|
5 | .text()
|
6 | .then(function (bodyText) {
|
7 | try {
|
8 | return JSON.parse(bodyText);
|
9 | }
|
10 | catch (err) {
|
11 | var parseError = err;
|
12 | parseError.name = 'ServerParseError';
|
13 | parseError.response = response;
|
14 | parseError.statusCode = response.status;
|
15 | parseError.bodyText = bodyText;
|
16 | throw parseError;
|
17 | }
|
18 | })
|
19 | .then(function (result) {
|
20 | if (response.status >= 300) {
|
21 | throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
|
22 | }
|
23 | if (!Array.isArray(result) &&
|
24 | !hasOwnProperty.call(result, 'data') &&
|
25 | !hasOwnProperty.call(result, 'errors')) {
|
26 | throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
|
27 | ? operations.map(function (op) { return op.operationName; })
|
28 | : operations.operationName, "'."));
|
29 | }
|
30 | return result;
|
31 | }); };
|
32 | }
|
33 |
|
\ | No newline at end of file |