forked from joepie91/node-bhttp
Fix assigning properties to non-writable error object. Updated PR section in README.md.
This commit is contained in:
parent
801096156f
commit
066c1f2213
|
@ -43,9 +43,9 @@ You can donate using Bitcoin, PayPal, Gratipay, Flattr, cash-in-mail, SEPA trans
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the `.coffee` files, not the `.js` files.
|
Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the `src/` files, not the `lib/` files.
|
||||||
|
|
||||||
Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
|
Simply run `npm run build` while developing, and it will watch for changes.
|
||||||
|
|
||||||
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
|
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
|
||||||
|
|
||||||
|
|
86
lib/bhttp.js
86
lib/bhttp.js
|
@ -4,13 +4,19 @@
|
||||||
// FIXME: Are arrays of streams in `data` correctly recognized as being streams?
|
// FIXME: Are arrays of streams in `data` correctly recognized as being streams?
|
||||||
// Core modules
|
// Core modules
|
||||||
|
|
||||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
||||||
|
|
||||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
||||||
|
|
||||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||||
|
|
||||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||||
|
|
||||||
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
||||||
|
|
||||||
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
||||||
|
|
||||||
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||||
|
|
||||||
var urlUtil = require("url");
|
var urlUtil = require("url");
|
||||||
|
|
||||||
|
@ -127,38 +133,31 @@ function assign() {
|
||||||
|
|
||||||
var ofTypes = function ofTypes(obj, types) {
|
var ofTypes = function ofTypes(obj, types) {
|
||||||
var match = false;
|
var match = false;
|
||||||
var _iteratorNormalCompletion = true;
|
|
||||||
var _didIteratorError = false;
|
var _iterator = _createForOfIteratorHelper(types),
|
||||||
var _iteratorError = undefined;
|
_step;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var _iterator = types[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||||
var type = _step.value;
|
var type = _step.value;
|
||||||
match = match || obj instanceof type;
|
match = match || obj instanceof type;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError = true;
|
_iterator.e(err);
|
||||||
_iteratorError = err;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
_iterator.f();
|
||||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
||||||
_iterator.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError) {
|
|
||||||
throw _iteratorError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
};
|
};
|
||||||
|
|
||||||
var addErrorData = function addErrorData(err, request, response, requestState) {
|
var addErrorData = function addErrorData(err, request, response, requestState) {
|
||||||
err.request = request;
|
// 'errors' lib uses Object.defineProperty, non-writable by default
|
||||||
err.response = response;
|
return Object.assign({}, err, {
|
||||||
err.requestState = requestState;
|
request: request,
|
||||||
return err;
|
response: response,
|
||||||
|
requestState: requestState
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var isStream = function isStream(obj) {
|
var isStream = function isStream(obj) {
|
||||||
|
@ -372,12 +371,11 @@ var preparePayload = function preparePayload(request, response, requestState) {
|
||||||
fieldValue = [fieldValue];
|
fieldValue = [fieldValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
var _iteratorNormalCompletion2 = true;
|
var _iterator2 = _createForOfIteratorHelper(fieldValue),
|
||||||
var _didIteratorError2 = false;
|
_step2;
|
||||||
var _iteratorError2 = undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var _iterator2 = fieldValue[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||||
var valueElement = _step2.value;
|
var valueElement = _step2.value;
|
||||||
var streamOptions;
|
var streamOptions;
|
||||||
|
|
||||||
|
@ -391,18 +389,9 @@ var preparePayload = function preparePayload(request, response, requestState) {
|
||||||
formDataObject.append(fieldName, valueElement, streamOptions);
|
formDataObject.append(fieldName, valueElement, streamOptions);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError2 = true;
|
_iterator2.e(err);
|
||||||
_iteratorError2 = err;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
_iterator2.f();
|
||||||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
||||||
_iterator2.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError2) {
|
|
||||||
throw _iteratorError2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,29 +580,20 @@ var processResponse = function processResponse(request, response, requestState)
|
||||||
if (request.cookieJar != null && response.headers["set-cookie"] != null) {
|
if (request.cookieJar != null && response.headers["set-cookie"] != null) {
|
||||||
var promises = function () {
|
var promises = function () {
|
||||||
var result = [];
|
var result = [];
|
||||||
var _iteratorNormalCompletion3 = true;
|
|
||||||
var _didIteratorError3 = false;
|
var _iterator3 = _createForOfIteratorHelper(response.headers["set-cookie"]),
|
||||||
var _iteratorError3 = undefined;
|
_step3;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var _iterator3 = response.headers["set-cookie"][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
||||||
var cookieHeader = _step3.value;
|
var cookieHeader = _step3.value;
|
||||||
debugResponse("storing cookie: %s", cookieHeader);
|
debugResponse("storing cookie: %s", cookieHeader);
|
||||||
result.push(request.cookieJar.set(cookieHeader, request.url));
|
result.push(request.cookieJar.set(cookieHeader, request.url));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError3 = true;
|
_iterator3.e(err);
|
||||||
_iteratorError3 = err;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
_iterator3.f();
|
||||||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
||||||
_iterator3.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError3) {
|
|
||||||
throw _iteratorError3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
10
src/bhttp.js
10
src/bhttp.js
|
@ -115,10 +115,12 @@ const ofTypes = function(obj, types) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const addErrorData = function(err, request, response, requestState) {
|
const addErrorData = function(err, request, response, requestState) {
|
||||||
err.request = request;
|
// 'errors' lib uses Object.defineProperty, non-writable by default
|
||||||
err.response = response;
|
return Object.assign({}, err, {
|
||||||
err.requestState = requestState;
|
request,
|
||||||
return err;
|
response,
|
||||||
|
requestState,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const isStream = obj => (obj != null) && (ofTypes(obj, [stream.Readable, stream.Duplex, stream.Transform]) || obj.hasOwnProperty("_bhttpStreamWrapper"));
|
const isStream = obj => (obj != null) && (ofTypes(obj, [stream.Readable, stream.Duplex, stream.Transform]) || obj.hasOwnProperty("_bhttpStreamWrapper"));
|
||||||
|
|
Loading…
Reference in a new issue