@commercetools/sdk-middleware-http
Advanced tools
Comparing version 4.0.5 to 4.0.6
@@ -322,6 +322,11 @@ 'use strict'; | ||
return; | ||
} | ||
if (res.status === 503 && enableRetry) if (retryCount < maxRetries) { | ||
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay)); | ||
retryCount += 1; | ||
return; | ||
} // Server responded with an error. Try to parse it as JSON, then | ||
// return a proper error type with all necessary meta information. | ||
res.text().then(function (text) { | ||
@@ -340,2 +345,3 @@ // Try to parse the error response as JSON | ||
originalRequest: request, | ||
retryCount: retryCount, | ||
headers: parseHeaders(res.headers) | ||
@@ -342,0 +348,0 @@ }, _typeof(parsed) === 'object' ? { |
@@ -318,6 +318,11 @@ function _typeof(obj) { | ||
return; | ||
} | ||
if (res.status === 503 && enableRetry) if (retryCount < maxRetries) { | ||
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay)); | ||
retryCount += 1; | ||
return; | ||
} // Server responded with an error. Try to parse it as JSON, then | ||
// return a proper error type with all necessary meta information. | ||
res.text().then(function (text) { | ||
@@ -336,2 +341,3 @@ // Try to parse the error response as JSON | ||
originalRequest: request, | ||
retryCount: retryCount, | ||
headers: parseHeaders(res.headers) | ||
@@ -338,0 +344,0 @@ }, _typeof(parsed) === 'object' ? { |
@@ -324,6 +324,11 @@ (function (global, factory) { | ||
return; | ||
} | ||
if (res.status === 503 && enableRetry) if (retryCount < maxRetries) { | ||
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay)); | ||
retryCount += 1; | ||
return; | ||
} // Server responded with an error. Try to parse it as JSON, then | ||
// return a proper error type with all necessary meta information. | ||
res.text().then(function (text) { | ||
@@ -342,2 +347,3 @@ // Try to parse the error response as JSON | ||
originalRequest: request, | ||
retryCount: retryCount, | ||
headers: parseHeaders(res.headers) | ||
@@ -344,0 +350,0 @@ }, _typeof(parsed) === 'object' ? { |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.CommercetoolsSdkMiddlewareHttp={})}(this,function(e){"use strict";function m(e){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function q(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},r=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),r.forEach(function(e){var r,t,n;r=o,n=i[t=e],t in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n})}return o}function S(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],0<=r.indexOf(t)||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],0<=r.indexOf(t)||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var r=require("./_global"),i=require("./_inherit-if-required"),t=require("./_object-dp").f,n=require("./_object-gopn").f,a=require("./_is-regexp"),s=require("./_flags"),u=r.RegExp,c=u,l=u.prototype,o=/a/g,f=/a/g,p=new u(o)!==o;if(require("./_descriptors")&&(!p||require("./_fails")(function(){return f[require("./_wks")("match")]=!1,u(o)!=o||u(f)==f||"/a/i"!=u(o,"i")}))){u=function(e,r){var t=this instanceof u,n=a(e),o=void 0===r;return!t&&n&&e.constructor===u&&o?e:i(p?new c(n&&!o?e.source:e,r):c((n=e instanceof u)?e.source:e,n&&o?s.call(e):r),t?this:l,u)};for(var d=function(r){r in u||t(u,r,{configurable:!0,get:function(){return c[r]},set:function(e){c[r]=e}})},h=n(c),y=0;h.length>y;)d(h[y++]);(l.constructor=u).prototype=l,require("./_redefine")(r,"RegExp",u)}require("./_set-species")("RegExp"),require("./_fix-re-wks")("match",1,function(n,o,e){return[function(e){var r=n(this),t=null==e?void 0:e[o];return void 0!==t?t.call(e,r):new RegExp(e)[o](String(r))},e]});var g=require("./_object-dp").f,b=Function.prototype,v=/^\s*function ([^ (]*)/,_="name";_ in b||require("./_descriptors")&&g(b,_,{configurable:!0,get:function(){try{return(""+this).match(v)[1]}catch(e){return""}}}),require("./_descriptors")&&"g"!=/./g.flags&&require("./_object-dp").f(RegExp.prototype,"flags",{configurable:!0,get:require("./_flags")}),require("./es6.regexp.flags");var w=require("./_an-object"),L=require("./_flags"),O=require("./_descriptors"),j="toString",x=/./[j],R=function(e){require("./_redefine")(RegExp.prototype,j,e,!0)};require("./_fails")(function(){return"/a/b"!=x.call({source:"a",flags:"b"})})?R(function(){var e=w(this);return"/".concat(e.source,"/","flags"in e?e.flags:!O&&e instanceof RegExp?L.call(e):void 0)}):x.name!=j&&R(function(){return x.call(this)}),require("./_fix-re-wks")("replace",2,function(o,i,a){return[function(e,r){var t=o(this),n=null==e?void 0:e[i];return void 0!==n?n.call(e,t,r):a.call(String(t),e,r)},a]});var C=require("./_export");function E(e,r){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.status=this.statusCode=this.code=e,this.message=r,Object.assign(this,t),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function M(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,0].concat(r))}function T(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this].concat(r))}function k(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,400].concat(r))}function A(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,401].concat(r))}function P(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,403].concat(r))}function D(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,404].concat(r))}function H(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,409].concat(r))}function N(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,500].concat(r))}function B(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,503].concat(r))}function V(e){switch(e){case 0:return M;case 400:return k;case 401:return A;case 403:return P;case 404:return D;case 409:return H;case 500:return N;case 503:return B;default:return}}C(C.S+C.F,"Object",{assign:require("./_object-assign")});for(var z=Object.freeze({NetworkError:M,HttpError:T,BadRequest:k,Unauthorized:A,Forbidden:P,NotFound:D,ConcurrentModification:H,InternalServerError:N,ServiceUnavailable:B,default:V}),F=require("./es6.array.iterator"),G=require("./_object-keys"),I=require("./_redefine"),U=require("./_global"),J=require("./_hide"),$=require("./_iterators"),K=require("./_wks"),Q=K("iterator"),W=K("toStringTag"),X=$.Array,Y={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},Z=G(Y),ee=0;ee<Z.length;ee++){var re,te=Z[ee],ne=Y[te],oe=U[te],ie=oe&&oe.prototype;if(ie&&(ie[Q]||J(ie,Q,X),ie[W]||J(ie,W,te),$[te]=X,ne))for(re in F)ie[re]||I(ie,re,F[re],!0)}function ae(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach(function(e,r){t[r]=e}),t}function se(e,r){r&&(e.headers.authorization&&(e.headers.authorization=["Bearer ********"]),e.headers.Authorization&&(e.headers.Authorization=["Bearer ********"]))}e.errors=z,e.createHttpMiddleware=function(e){var o=e.host,i=e.credentialsMode,l=e.includeResponseHeaders,f=e.includeOriginalRequest,r=e.maskSensitiveHeaderData,p=void 0===r||r,d=e.enableRetry,t=e.retryConfig,n=(t=void 0===t?{}:t).maxRetries,h=void 0===n?10:n,a=t.backoff,y=void 0===a||a,s=t.retryDelay,g=void 0===s?200:s,u=t.maxDelay,b=void 0===u?1/0:u,v=e.fetch;if(!v&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");return v||(v=fetch),function(c){return function(a,s){var e=o.replace(/\/$/,"")+a.uri,r="string"==typeof a.body||Buffer.isBuffer(a.body)?a.body:JSON.stringify(a.body||void 0),t=q({"Content-Type":["application/json"]},a.headers,r?{"Content-Length":Buffer.byteLength(r).toString()}:null),n=q({method:a.method,headers:t},i?{credentials:i}:{},r?{body:r}:null),u=0;!function i(){v(e,n).then(function(o){o.ok?o.json().then(function(e){var r=q({},s,{body:e,statusCode:o.status});l&&(r.headers=ae(o.headers)),f&&(r.request=q({},n),se(r.request,p)),c(a,r)}):o.text().then(function(e){var r;try{r=JSON.parse(e)}catch(t){r=e}var t=function(e){var r=e.statusCode,t=e.message,n=S(e,["statusCode","message"]),o=t||"Unexpected non-JSON error response";404===r&&(o="URI not found: ".concat(n.originalRequest.uri));var i=V(r);return i?new i(o,n):new T(r,o,n)}(q({statusCode:o.status,originalRequest:a,headers:ae(o.headers)},"object"===m(r)?{message:r.message,body:r}:{message:r,body:r}));se(t.originalRequest,p);var n=q({},s,{error:t,statusCode:o.status});c(a,n)})},function(e){if(d&&u<h)return setTimeout(i,(r=u,t=g,n=b,y&&0!==r?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,r)),n):t)),void(u+=1);var r,t,n,o=new M(e.message,{originalRequest:a,retryCount:u});se(o.originalRequest,p),c(a,q({},s,{error:o,statusCode:0}))})}()}}},e.getErrorByCode=V,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.CommercetoolsSdkMiddlewareHttp={})}(this,function(e){"use strict";function m(e){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function q(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},r=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),r.forEach(function(e){var r,t,n;r=o,n=i[t=e],t in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n})}return o}function S(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],0<=r.indexOf(t)||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],0<=r.indexOf(t)||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var r=require("./_global"),i=require("./_inherit-if-required"),t=require("./_object-dp").f,n=require("./_object-gopn").f,a=require("./_is-regexp"),u=require("./_flags"),s=r.RegExp,c=s,l=s.prototype,o=/a/g,f=/a/g,p=new s(o)!==o;if(require("./_descriptors")&&(!p||require("./_fails")(function(){return f[require("./_wks")("match")]=!1,s(o)!=o||s(f)==f||"/a/i"!=s(o,"i")}))){s=function(e,r){var t=this instanceof s,n=a(e),o=void 0===r;return!t&&n&&e.constructor===s&&o?e:i(p?new c(n&&!o?e.source:e,r):c((n=e instanceof s)?e.source:e,n&&o?u.call(e):r),t?this:l,s)};for(var d=function(r){r in s||t(s,r,{configurable:!0,get:function(){return c[r]},set:function(e){c[r]=e}})},h=n(c),y=0;h.length>y;)d(h[y++]);(l.constructor=s).prototype=l,require("./_redefine")(r,"RegExp",s)}require("./_set-species")("RegExp"),require("./_fix-re-wks")("match",1,function(n,o,e){return[function(e){var r=n(this),t=null==e?void 0:e[o];return void 0!==t?t.call(e,r):new RegExp(e)[o](String(r))},e]});var g=require("./_object-dp").f,v=Function.prototype,b=/^\s*function ([^ (]*)/,_="name";_ in v||require("./_descriptors")&&g(v,_,{configurable:!0,get:function(){try{return(""+this).match(b)[1]}catch(e){return""}}}),require("./_descriptors")&&"g"!=/./g.flags&&require("./_object-dp").f(RegExp.prototype,"flags",{configurable:!0,get:require("./_flags")}),require("./es6.regexp.flags");var w=require("./_an-object"),L=require("./_flags"),O=require("./_descriptors"),j="toString",x=/./[j],C=function(e){require("./_redefine")(RegExp.prototype,j,e,!0)};require("./_fails")(function(){return"/a/b"!=x.call({source:"a",flags:"b"})})?C(function(){var e=w(this);return"/".concat(e.source,"/","flags"in e?e.flags:!O&&e instanceof RegExp?L.call(e):void 0)}):x.name!=j&&C(function(){return x.call(this)}),require("./_fix-re-wks")("replace",2,function(o,i,a){return[function(e,r){var t=o(this),n=null==e?void 0:e[i];return void 0!==n?n.call(e,t,r):a.call(String(t),e,r)},a]});var R=require("./_export");function E(e,r){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.status=this.statusCode=this.code=e,this.message=r,Object.assign(this,t),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function M(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,0].concat(r))}function T(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this].concat(r))}function k(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,400].concat(r))}function A(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,401].concat(r))}function P(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,403].concat(r))}function D(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,404].concat(r))}function H(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,409].concat(r))}function N(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,500].concat(r))}function B(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];E.call.apply(E,[this,503].concat(r))}function V(e){switch(e){case 0:return M;case 400:return k;case 401:return A;case 403:return P;case 404:return D;case 409:return H;case 500:return N;case 503:return B;default:return}}R(R.S+R.F,"Object",{assign:require("./_object-assign")});for(var z=Object.freeze({NetworkError:M,HttpError:T,BadRequest:k,Unauthorized:A,Forbidden:P,NotFound:D,ConcurrentModification:H,InternalServerError:N,ServiceUnavailable:B,default:V}),F=require("./es6.array.iterator"),G=require("./_object-keys"),I=require("./_redefine"),U=require("./_global"),J=require("./_hide"),$=require("./_iterators"),K=require("./_wks"),Q=K("iterator"),W=K("toStringTag"),X=$.Array,Y={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},Z=G(Y),ee=0;ee<Z.length;ee++){var re,te=Z[ee],ne=Y[te],oe=U[te],ie=oe&&oe.prototype;if(ie&&(ie[Q]||J(ie,Q,X),ie[W]||J(ie,W,te),$[te]=X,ne))for(re in F)ie[re]||I(ie,re,F[re],!0)}function ae(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach(function(e,r){t[r]=e}),t}function ue(e,r,t,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*r*Math.pow(2,e)),o):r}function se(e,r){r&&(e.headers.authorization&&(e.headers.authorization=["Bearer ********"]),e.headers.Authorization&&(e.headers.Authorization=["Bearer ********"]))}e.errors=z,e.createHttpMiddleware=function(e){var o=e.host,c=e.credentialsMode,l=e.includeResponseHeaders,f=e.includeOriginalRequest,r=e.maskSensitiveHeaderData,p=void 0===r||r,d=e.enableRetry,t=e.retryConfig,n=(t=void 0===t?{}:t).maxRetries,h=void 0===n?10:n,i=t.backoff,y=void 0===i||i,a=t.retryDelay,g=void 0===a?200:a,u=t.maxDelay,v=void 0===u?1/0:u,b=e.fetch;if(!b&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");return b||(b=fetch),function(s){return function(i,a){var e=o.replace(/\/$/,"")+i.uri,r="string"==typeof i.body||Buffer.isBuffer(i.body)?i.body:JSON.stringify(i.body||void 0),t=q({"Content-Type":["application/json"]},i.headers,r?{"Content-Length":Buffer.byteLength(r).toString()}:null),n=q({method:i.method,headers:t},c?{credentials:c}:{},r?{body:r}:null),u=0;!function t(){b(e,n).then(function(o){if(!o.ok)return 503===o.status&&d&&u<h?(setTimeout(t,ue(u,g,0,y,v)),void(u+=1)):void o.text().then(function(e){var r;try{r=JSON.parse(e)}catch(t){r=e}var t=function(e){var r=e.statusCode,t=e.message,n=S(e,["statusCode","message"]),o=t||"Unexpected non-JSON error response";404===r&&(o="URI not found: ".concat(n.originalRequest.uri));var i=V(r);return i?new i(o,n):new T(r,o,n)}(q({statusCode:o.status,originalRequest:i,retryCount:u,headers:ae(o.headers)},"object"===m(r)?{message:r.message,body:r}:{message:r,body:r}));se(t.originalRequest,p);var n=q({},a,{error:t,statusCode:o.status});s(i,n)});o.json().then(function(e){var r=q({},a,{body:e,statusCode:o.status});l&&(r.headers=ae(o.headers)),f&&(r.request=q({},n),se(r.request,p)),s(i,r)})},function(e){if(d&&u<h)return setTimeout(t,ue(u,g,0,y,v)),void(u+=1);var r=new M(e.message,{originalRequest:i,retryCount:u});se(r.originalRequest,p),s(i,q({},a,{error:r,statusCode:0}))})}()}}},e.getErrorByCode=V,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=commercetools-sdk-middleware-http.umd.min.js.map |
@@ -7,3 +7,3 @@ { | ||
"name": "@commercetools/sdk-middleware-http", | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"description": "Middleware for http requests, to use with @commercetools/sdk-client", | ||
@@ -41,3 +41,4 @@ "keywords": [ | ||
"node-fetch": "2.2.0" | ||
} | ||
}, | ||
"gitHead": "5846dc1df83dead39c0b4f4c1db2921e3e0f0dad" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52528
11
1009