async function SendRequest(action, uri, data, formattedValue, maxPageSize) { if (!RegExp(action, "g").test("POST PATCH PUT GET DELETE")) { throw new Error("Sdk.request: action parameter must be one of the following: " + "POST, PATCH, PUT, GET, or DELETE."); } if (!typeof uri === "string") { throw new Error("Sdk.request: uri parameter must be a string."); } if ((RegExp(action, "g").test("POST PATCH PUT")) && (data === null || data === undefined)) { throw new Error("Sdk.request: data parameter must not be null for operations that create or modify data."); } uri = HandleProxy(uri); return new Promise(function (resolve, reject) { var request = new XMLHttpRequest(); request.open(action, encodeURI(uri), true); request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Content-Type", "application/json; charset=utf-8"); request.setRequestHeader("Authorization", "Bearer " + token); request.setRequestHeader("Ocp-Apim-Subscription-Key", '{{settings.Ocp-Apim-Subscription-Key}}'); request.onreadystatechange = function () { if (this.readyState === 4) { request.onreadystatechange = null; switch (this.status) { case 200: // Success with content returned in response body. case 204: // Success with no content returned in response body. resolve(this); break; default: // All other statuses are unexpected so are treated like errors. var error; try { throw new Error(JSON.parse(request.response)); } catch (e) { error = e; } var popupNotification = $("#popupNotification").kendoNotification().data("kendoNotification"); const errorMessage = "Something went wrong. If this issue persists, please contact clientservices@qic.com"; popupNotification.show(errorMessage, "error"); reject(errorMessage); break; } } }; request.send(JSON.stringify(data)); }) }; function HandleProxy(uri) { var proxyContact = localStorage.getItem('contactId'); if (proxyContact != null) { // check if the uri already has parameters var uriParams = uri.includes("?") ? "&" : "?"; // add the proxy parameter to the uri return uri + uriParams + "proxy=" + proxyContact; } return uri; }