UNPKG

mongodb-stitch

Version:

[![Join the chat at https://gitter.im/mongodb/stitch](https://badges.gitter.im/mongodb/stitch.svg)](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

62 lines 2.96 kB
var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../../internal/common/StitchErrorUtils", "../../StitchRequestErrorCode", "../../StitchError", "../../StitchRequestError", "./BasicRequest"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var StitchErrorUtils_1 = require("../../internal/common/StitchErrorUtils"); var StitchRequestErrorCode_1 = require("../../StitchRequestErrorCode"); var StitchError_1 = __importDefault(require("../../StitchError")); var StitchRequestError_1 = __importDefault(require("../../StitchRequestError")); var BasicRequest_1 = require("./BasicRequest"); function inspectResponse(response) { if (response.statusCode >= 200 && response.statusCode < 300) { return response; } return StitchErrorUtils_1.handleRequestError(response); } var StitchRequestClient = (function () { function StitchRequestClient(baseUrl, transport) { this.baseUrl = baseUrl; this.transport = transport; } StitchRequestClient.prototype.doRequest = function (stitchReq) { return this.transport .roundTrip(this.buildRequest(stitchReq)) .catch(function (error) { throw new StitchRequestError_1.default(error, StitchRequestErrorCode_1.StitchRequestErrorCode.TRANSPORT_ERROR); }) .then(inspectResponse); }; StitchRequestClient.prototype.doStreamRequest = function (stitchReq, open, retryRequest) { if (open === void 0) { open = true; } return this.transport .stream(this.buildRequest(stitchReq), open, retryRequest) .catch(function (error) { if (error instanceof StitchError_1.default) { throw error; } throw new StitchRequestError_1.default(error, StitchRequestErrorCode_1.StitchRequestErrorCode.TRANSPORT_ERROR); }); }; StitchRequestClient.prototype.buildRequest = function (stitchReq) { return new BasicRequest_1.BasicRequest.Builder() .withMethod(stitchReq.method) .withUrl("" + this.baseUrl + stitchReq.path) .withHeaders(stitchReq.headers) .withBody(stitchReq.body) .build(); }; return StitchRequestClient; }()); exports.default = StitchRequestClient; }); //# sourceMappingURL=StitchRequestClient.js.map