Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.170/page_editor/app/services/serviceFetch",["module","exports","require","frontend-js-web","../actions/index","../config/constants/serviceNetworkStatusTypes","../config/index"],(function(e,r,t){window;{Object.defineProperty(r,"__esModule",{value:!0}),r.default=function serviceFetch(e,r={body:{}},t,{requestGenerateDraft:a=!1}={requestGenerateDraft:!1}){let{body:i={},method:s}=r,u=function _objectWithoutProperties(e,r){if(null==e)return{};var t,n,o=function _objectWithoutPropertiesLoose(e,r){if(null==e)return{};var t,n,o={},c=Object.keys(e);for(n=0;n<c.length;n++)t=c[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(n=0;n<c.length;n++)t=c[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(r,["body","method"]);a&&t((0,o.updateNetwork)({status:c.SERVICE_NETWORK_STATUS_TYPES.savingDraft}));return(0,n.fetch)(e,_objectSpread(_objectSpread({},u),{},{body:getFormData(i),method:s||"POST"})).then((e=>new Promise(((r,t)=>{e.clone().json().then((t=>r([e,t]))).catch((()=>e.clone().text())).then((t=>r([e,t]))).catch(t)})))).then((([e,r])=>"object"!=typeof r||"exception"in r?handleErroredResponse(Liferay.Language.get("an-unexpected-error-occurred"),t):"error"in r?handleErroredResponse(Liferay.Language.get(r.error),t):e.status>=400?handleErroredResponse(Liferay.Language.get("an-unexpected-error-occurred"),t):(a&&t((0,o.updateNetwork)({error:null,status:c.SERVICE_NETWORK_STATUS_TYPES.draftSaved})),r)))};var n=t("frontend-js-web"),o=t("../actions/index"),c=t("../config/constants/serviceNetworkStatusTypes"),a=t("../config/index");function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){_defineProperty(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function getFormData(e){const r=new FormData;return Object.entries(e).forEach((([e,t])=>{r.append("".concat(a.config.portletNamespace).concat(e),t)})),r}function handleErroredResponse(e,r){return r((0,o.updateNetwork)({error:e,status:c.SERVICE_NETWORK_STATUS_TYPES.error})),Promise.reject(e)}}}));
//# sourceMappingURL=serviceFetch.js.map