From 1282d3b0599ce2b63ef4a1ac3e34d432bf16c156 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 16 Aug 2021 14:23:24 -0400 Subject: [PATCH] Don't use a util function for a thing that exists 1x in the code --- modules/core/file_fetcher.js | 11 +++++++++-- modules/util/index.js | 1 - modules/util/util.js | 11 ----------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/modules/core/file_fetcher.js b/modules/core/file_fetcher.js index 5ba723b81..a8196f14e 100644 --- a/modules/core/file_fetcher.js +++ b/modules/core/file_fetcher.js @@ -1,4 +1,3 @@ -import { utilFetchJson } from '../util/util'; import parseVersion from 'vparse'; // Double check this resolves to iD's `package.json` import packageJSON from '../../package.json'; @@ -60,7 +59,15 @@ export function coreFileFetcher() { let prom = _inflight[url]; if (!prom) { - _inflight[url] = prom = utilFetchJson(url) + _inflight[url] = prom = fetch(url) + .then(response => { + // fetch in PhantomJS tests may return ok=false and status=0 even if it's okay + if ((!response.ok && response.status !== 0) || !response.json) { + throw new Error(response.status + ' ' + response.statusText); + } + if (response.status === 204 || response.status === 205) return; // No Content, Reset Content + return response.json(); + }) .then(result => { delete _inflight[url]; if (!result) { diff --git a/modules/util/index.js b/modules/util/index.js index 3c0836aed..45e1266ef 100644 --- a/modules/util/index.js +++ b/modules/util/index.js @@ -27,7 +27,6 @@ export { utilEntityOrMemberSelector } from './util'; export { utilEntityOrDeepMemberSelector } from './util'; export { utilEntitySelector } from './util'; export { utilFastMouse } from './util'; -export { utilFetchJson } from './util'; export { utilFunctor } from './util'; export { utilGetAllNodes } from './util'; export { utilGetSetValue } from './get_set_value'; diff --git a/modules/util/util.js b/modules/util/util.js index 53c8c0d24..388ba7261 100644 --- a/modules/util/util.js +++ b/modules/util/util.js @@ -580,14 +580,3 @@ export function utilUnicodeCharsCount(str) { export function utilUnicodeCharsTruncated(str, limit) { return Array.from(str).slice(0, limit).join(''); } - -// Variation of d3.json (https://github.com/d3/d3-fetch/blob/master/src/json.js) -export function utilFetchJson(resourse, init) { - return fetch(resourse, init) - .then((response) => { - // fetch in PhantomJS tests may return ok=false and status=0 even if it's okay - if ((!response.ok && response.status !== 0) || !response.json) throw new Error(response.status + ' ' + response.statusText); - if (response.status === 204 || response.status === 205) return; - return response.json(); - }); -}