MCPcopy Index your code
hub / github.com/dabbott/javascript-playgrounds / get

Function get

utils/Networking.js:4–26  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

2
3// https://github.com/github/fetch (MIT)
4export const get = (url) => {
5 return new Promise((resolve, reject) => {
6 var xhr = new XMLHttpRequest()
7
8 xhr.onload = () => {
9 const body = 'response' in xhr ? xhr.response : xhr.responseText
10
11 if (xhr.status >= 200 && xhr.status < 300) {
12 resolve(body, xhr)
13 } else {
14 reject(xhr)
15 }
16 }
17
18 xhr.onerror = xhr.ontimeout = () => {
19 reject(new TypeError('Network request failed'))
20 }
21
22 xhr.open('GET', url, true)
23
24 xhr.send()
25 })
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected