UNPKG

2.81 kBSource Map (JSON)View Raw
1{"version":3,"file":"parseAndCheckHttpResponse.js","sourceRoot":"","sources":["../../../src/link/http/parseAndCheckHttpResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEpC,IAAA,cAAc,GAAK,MAAM,CAAC,SAAS,eAArB,CAAsB;AAQ5C,MAAM,UAAU,yBAAyB,CACvC,UAAmC;IAEnC,OAAO,UAAC,QAAkB,IAAK,OAAA,QAAQ;SACpC,IAAI,EAAE;SACN,IAAI,CAAC,UAAA,QAAQ;QACZ,IAAI;YACF,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC7B;QAAC,OAAO,GAAG,EAAE;YACZ,IAAM,UAAU,GAAG,GAAuB,CAAC;YAC3C,UAAU,CAAC,IAAI,GAAG,kBAAkB,CAAC;YACrC,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC/B,UAAU,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;YACxC,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC/B,MAAM,UAAU,CAAC;SAClB;IACH,CAAC,CAAC;SACD,IAAI,CAAC,UAAC,MAAW;QAChB,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;YAE1B,gBAAgB,CACd,QAAQ,EACR,MAAM,EACN,wDAAiD,QAAQ,CAAC,MAAM,CAAE,CACnE,CAAC;SACH;QAED,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YACtB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;YACpC,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EACtC;YAEA,gBAAgB,CACd,QAAQ,EACR,MAAM,EACN,iDACE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;gBACvB,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,UAAA,EAAE,IAAI,OAAA,EAAE,CAAC,aAAa,EAAhB,CAAgB,CAAC;gBACxC,CAAC,CAAC,UAAU,CAAC,aAAa,OAC1B,CACL,CAAC;SACH;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,EAzC2B,CAyC3B,CAAC;AACP,CAAC","sourcesContent":["import { Operation } from '../core';\nimport { throwServerError } from '../utils';\n\nconst { hasOwnProperty } = Object.prototype;\n\nexport type ServerParseError = Error & {\n response: Response;\n statusCode: number;\n bodyText: string;\n};\n\nexport function parseAndCheckHttpResponse(\n operations: Operation | Operation[],\n) {\n return (response: Response) => response\n .text()\n .then(bodyText => {\n try {\n return JSON.parse(bodyText);\n } catch (err) {\n const parseError = err as ServerParseError;\n parseError.name = 'ServerParseError';\n parseError.response = response;\n parseError.statusCode = response.status;\n parseError.bodyText = bodyText;\n throw parseError;\n }\n })\n .then((result: any) => {\n if (response.status >= 300) {\n // Network error\n throwServerError(\n response,\n result,\n `Response not successful: Received status code ${response.status}`,\n );\n }\n\n if (\n !Array.isArray(result) &&\n !hasOwnProperty.call(result, 'data') &&\n !hasOwnProperty.call(result, 'errors')\n ) {\n // Data error\n throwServerError(\n response,\n result,\n `Server response was missing for query '${\n Array.isArray(operations)\n ? operations.map(op => op.operationName)\n : operations.operationName\n }'.`,\n );\n }\n return result;\n });\n}\n"]}
\No newline at end of file