Comparing version 2.0.0-beta18 to 2.0.0-beta19
@@ -171,3 +171,5 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var handleError = function handleError(e) { | ||
throw Error(e); | ||
var message = 'request network error: ' + e + ', address: ' + address; | ||
throw new Error(message); | ||
}; | ||
@@ -174,0 +176,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.dtHttp=t():e.dtHttp=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){r(1),e.exports=r(1)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){if(!e)return{};var t=function(){var t=e.split("\r\n"),r={};return t.forEach(function(e){var t=e.indexOf(": ");if(t>0){var n=e.substring(0,t),o=e.substring(t+2);r[n.toLowerCase()]=o.toLowerCase()}}),{v:r}}();return"object"==typeof t?t.v:void 0}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(2),i="undefined"==typeof XMLHttpRequest?r(3):XMLHttpRequest,s=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?Promise:arguments[1];n(this,e),this.httpHeaders=new Map,this.middlewares=new Set,this.url=t,this.promise=r}return u(e,[{key:"setHeader",value:function(e,t){this.httpHeaders.set(e,t)}},{key:"applyMiddleware",value:function(e){this.middlewares.add(e)}},{key:"request",value:function(e,t,r){var n=this,u=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return new this.promise(function(a,s){var f=""+n.url+t,c=new i,d=function(){var e=c.status;c.readyState===c.DONE&&(e>0?!function(){var t=o(c.getAllResponseHeaders()),r=t["content-type"],u=r&&r.indexOf("json")>-1&&c.response.length>0?JSON.parse(c.response):c.response,i={status:e,headers:t,body:u};n.middlewares.size>0?n.middlewares.forEach(function(e){return e({request:c,response:i,resolve:a,reject:s})}):a(i)}():s(Error("request has been failed")))},p=function(e){throw Error(e)};c.withCredentials=u.withCredentials||!1,c.onreadystatechange=d,c.onerror=p,c.open(e,f),n.httpHeaders.forEach(function(e,t){c.setRequestHeader(t,e)}),u.headers&&u.headers.forEach(function(e,t){c.setRequestHeader(t,e)});var l=u.headers?u.headers.get("Content-Type"):n.httpHeaders.get("Content-Type"),y=l&&l.indexOf("json")>-1?JSON.stringify(r):r;c.send(y)})}},{key:"get",value:function(e,t,r){var n=e;if(t){var o=encodeURI(a.JSONToQueryParams(t));n=e+"?"+o}return this.request("GET",n,null,r)}},{key:"post",value:function(e,t,r){return this.request("POST",e,t,r)}},{key:"put",value:function(e,t,r){return this.request("PUT",e,t,r)}},{key:"patch",value:function(e,t,r){return this.request("PATCH",e,t,r)}},{key:"del",value:function(e,t){return this.request("DELETE",e,t)}}]),e}();t["default"]=s,e.exports=t["default"]},function(e,t){"use strict";function r(e,t){return e?Object.keys(e).map(function(n){var o=e[n];return n&&"undefined"!=typeof n&&o&&"undefined"!=typeof o?!(o instanceof Object)||o instanceof Array||o instanceof Function?t?t+"["+n+"]="+o:n+"="+o:r(o,n):null}).filter(function(e){return!!e}).join("&"):void 0}function n(e){return r(e)}function o(e){return JSON.stringify(e)}function u(e){if("string"!=typeof e)return void 0;try{return JSON.parse(e)}catch(t){return e||void 0}}function a(e){return!Object.keys(e).length>0}function i(e,t,r){return e.filter(function(e){return e[t]===r})}function s(e,t,r){return i(e,t,r)[0]}function f(e,t){var r=e.slice();return r.splice(t,1),r}function c(e){var t=arguments.length<=1||void 0===arguments[1]?6e5:arguments[1],r=(new Date).getTime();return r-e>t}function d(e){return parseInt(e.replace(/ /g,"").replace(/-/g,"").replace(/\(/g,"").replace(/\)/g,""),0)}Object.defineProperty(t,"__esModule",{value:!0}),t.JSONToQueryParams=n,t.JSONToString=o,t.stringToJSON=u,t.isObjectEmpty=a,t.findInArray=i,t.getObjectInArray=s,t.popArray=f,t.isOlderThan=c,t.flatPhone=d;var p={string:{capitalize:function(e){return e.charAt(0).toUpperCase()+e.slice(1)}},date:{mask:function(e,t){var r=function(e){return("0"+e).slice(-2)},n=r(e.getDate()),o=r(e.getMonth()+1),u=r(e.getFullYear());return t.replace(/d/g,n).replace(/m/g,o).replace(/y/g,u)}}};t.format=p,t["default"]={JSONToQueryParams:n,JSONToString:o,stringToJSON:u,getObjectInArray:s,isObjectEmpty:a,findInArray:i,popArray:f,isOlderThan:c,flatPhone:d,format:p,isEmpty:a,formatDate:p.date.mask}},function(e,t){e.exports=XMLHttpRequest}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.dtHttp=t():e.dtHttp=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){r(1),e.exports=r(1)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){if(!e)return{};var t=function(){var t=e.split("\r\n"),r={};return t.forEach(function(e){var t=e.indexOf(": ");if(t>0){var n=e.substring(0,t),o=e.substring(t+2);r[n.toLowerCase()]=o.toLowerCase()}}),{v:r}}();return"object"==typeof t?t.v:void 0}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=r(2),i="undefined"==typeof XMLHttpRequest?r(3):XMLHttpRequest,s=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?Promise:arguments[1];n(this,e),this.httpHeaders=new Map,this.middlewares=new Set,this.url=t,this.promise=r}return a(e,[{key:"setHeader",value:function(e,t){this.httpHeaders.set(e,t)}},{key:"applyMiddleware",value:function(e){this.middlewares.add(e)}},{key:"request",value:function(e,t,r){var n=this,a=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return new this.promise(function(u,s){var f=""+n.url+t,c=new i,d=function(){var e=c.status;c.readyState===c.DONE&&(e>0?!function(){var t=o(c.getAllResponseHeaders()),r=t["content-type"],a=r&&r.indexOf("json")>-1&&c.response.length>0?JSON.parse(c.response):c.response,i={status:e,headers:t,body:a};n.middlewares.size>0?n.middlewares.forEach(function(e){return e({request:c,response:i,resolve:u,reject:s})}):u(i)}():s(Error("request has been failed")))},p=function(e){var t="request network error: "+e+", address: "+f;throw new Error(t)};c.withCredentials=a.withCredentials||!1,c.onreadystatechange=d,c.onerror=p,c.open(e,f),n.httpHeaders.forEach(function(e,t){c.setRequestHeader(t,e)}),a.headers&&a.headers.forEach(function(e,t){c.setRequestHeader(t,e)});var l=a.headers?a.headers.get("Content-Type"):n.httpHeaders.get("Content-Type"),y=l&&l.indexOf("json")>-1?JSON.stringify(r):r;c.send(y)})}},{key:"get",value:function(e,t,r){var n=e;if(t){var o=encodeURI(u.JSONToQueryParams(t));n=e+"?"+o}return this.request("GET",n,null,r)}},{key:"post",value:function(e,t,r){return this.request("POST",e,t,r)}},{key:"put",value:function(e,t,r){return this.request("PUT",e,t,r)}},{key:"patch",value:function(e,t,r){return this.request("PATCH",e,t,r)}},{key:"del",value:function(e,t){return this.request("DELETE",e,t)}}]),e}();t["default"]=s,e.exports=t["default"]},function(e,t){"use strict";function r(e,t){return e?Object.keys(e).map(function(n){var o=e[n];return n&&"undefined"!=typeof n&&o&&"undefined"!=typeof o?!(o instanceof Object)||o instanceof Array||o instanceof Function?t?t+"["+n+"]="+o:n+"="+o:r(o,n):null}).filter(function(e){return!!e}).join("&"):void 0}function n(e){return r(e)}function o(e){return JSON.stringify(e)}function a(e){if("string"!=typeof e)return void 0;try{return JSON.parse(e)}catch(t){return e||void 0}}function u(e){return!Object.keys(e).length>0}function i(e,t,r){return e.filter(function(e){return e[t]===r})}function s(e,t,r){return i(e,t,r)[0]}function f(e,t){var r=e.slice();return r.splice(t,1),r}function c(e){var t=arguments.length<=1||void 0===arguments[1]?6e5:arguments[1],r=(new Date).getTime();return r-e>t}function d(e){return parseInt(e.replace(/ /g,"").replace(/-/g,"").replace(/\(/g,"").replace(/\)/g,""),0)}Object.defineProperty(t,"__esModule",{value:!0}),t.JSONToQueryParams=n,t.JSONToString=o,t.stringToJSON=a,t.isObjectEmpty=u,t.findInArray=i,t.getObjectInArray=s,t.popArray=f,t.isOlderThan=c,t.flatPhone=d;var p={string:{capitalize:function(e){return e.charAt(0).toUpperCase()+e.slice(1)}},date:{mask:function(e,t){var r=function(e){return("0"+e).slice(-2)},n=r(e.getDate()),o=r(e.getMonth()+1),a=r(e.getFullYear());return t.replace(/d/g,n).replace(/m/g,o).replace(/y/g,a)}}};t.format=p,t["default"]={JSONToQueryParams:n,JSONToString:o,stringToJSON:a,getObjectInArray:s,isObjectEmpty:u,findInArray:i,popArray:f,isOlderThan:c,flatPhone:d,format:p,isEmpty:u,formatDate:p.date.mask}},function(e,t){e.exports=XMLHttpRequest}])}); |
@@ -107,3 +107,5 @@ 'use strict'; | ||
var handleError = function handleError(e) { | ||
throw Error(e); | ||
var message = 'request network error: ' + e + ', address: ' + address; | ||
throw new Error(message); | ||
}; | ||
@@ -110,0 +112,0 @@ |
{ | ||
"name": "dthttp", | ||
"version": "2.0.0-beta18", | ||
"version": "2.0.0-beta19", | ||
"description": "Simple class-based HTTP client with Promises", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -76,3 +76,5 @@ import { JSONToQueryParams } from '@dtrussia/utils.js'; | ||
const handleError = (e) => { | ||
throw Error(e); | ||
const message = `request network error: ${e}, address: ${address}`; | ||
throw new Error(message); | ||
}; | ||
@@ -79,0 +81,0 @@ |
27272
549