(method, url, { async = true, body, headers = {}, onload, onerror } = {})
| 73 | } |
| 74 | |
| 75 | function httpRequest(method, url, { async = true, body, headers = {}, onload, onerror } = {}) { |
| 76 | const xhr = new XMLHttpRequest(); |
| 77 | if (typeof onload === "function") { |
| 78 | xhr.onload = () => onload(xhr); |
| 79 | } |
| 80 | xhr.onerror = () => { |
| 81 | if (typeof onerror === "function") { |
| 82 | onerror(xhr); |
| 83 | } else { |
| 84 | console.error("Network error or request failure."); |
| 85 | } |
| 86 | }; |
| 87 | xhr.open(method, url, async); |
| 88 | Object.keys(headers).forEach((header) => xhr.setRequestHeader(header, headers[header])); |
| 89 | if (body !== undefined && body !== null) { |
| 90 | xhr.send(body); |
| 91 | } else { |
| 92 | xhr.send(); |
| 93 | } |
| 94 | return xhr; |
| 95 | } |
| 96 | |
| 97 | function isNullOrEmpty(value) { |
| 98 | return value === null || value === ""; |
no outgoing calls
no test coverage detected