MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / httpGetJson

Function httpGetJson

tooling/scripts/perf-desktop-runtime.mjs:156–181  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

154}
155
156function httpGetJson(url) {
157 return new Promise((resolvePromise, rejectPromise) => {
158 const req = http.get(url, (res) => {
159 let body = ''
160 res.setEncoding('utf8')
161 res.on('data', (chunk) => {
162 body += chunk
163 })
164 res.on('end', () => {
165 if ((res.statusCode ?? 500) >= 400) {
166 rejectPromise(new Error(`${url} returned HTTP ${res.statusCode}: ${body}`))
167 return
168 }
169 try {
170 resolvePromise(JSON.parse(body))
171 } catch (err) {
172 rejectPromise(err)
173 }
174 })
175 })
176 req.on('error', rejectPromise)
177 req.setTimeout(1000, () => {
178 req.destroy(new Error(`Timed out requesting ${url}`))
179 })
180 })
181}
182
183function formatIndex(index) {
184 return String(index).padStart(5, '0')

Callers 1

connectToElectronPageFunction · 0.70

Calls 2

onMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected